I am trying to make validation to accept only numbers (no letters), It works on the computer browser but stopes when using the mobile browser. Below is the code:
$(document).ready(function () {
const $input = document.querySelector("#phMidPane_ctl04_txtID");
const NUMBER_ALLOWED_CHARS_REGEXP = /[0-9\/]+/;
$input.addEventListener("keydown", event => {
console.log(NUMBER_ALLOWED_CHARS_REGEXP.test(event.key));
if (!NUMBER_ALLOWED_CHARS_REGEXP.test(event.key)) {
event.preventDefault();
}
});
$input.addEventListener("keypress", event => {
// alert(2);
if (!NUMBER_ALLOWED_CHARS_REGEXP.test(event.key)) {
event.preventDefault();
}
});
});