This commit is contained in:
cmdr2
2022-11-04 19:48:34 +05:30
parent c3129a40f1
commit 749c72e6a6
2 changed files with 18 additions and 6 deletions

View File

@ -342,3 +342,15 @@ function asyncDelay(timeout) {
setTimeout(resolve, timeout, true)
})
}
function preventNonNumericalInput(e) {
e = e || window.event;
let charCode = (typeof e.which == "undefined") ? e.keyCode : e.which;
let charStr = String.fromCharCode(charCode);
let re = e.target.getAttribute('pattern') || '^[0-9]+$'
re = new RegExp(re)
if (!charStr.match(re)) {
e.preventDefault();
}
}