onkeypress
seems to be working fine, but I'm having trouble getting onkeyup
to work. Any suggestions on how to make onkeyup
work properly?
https://jsfiddle.net/btykt0nk/
function isNumber(number_check) {
number_check = (number_check) ? number_check : window.event;
var charCode = (number_check.which) ? number_check.which : number_check.keyCode;
console.log(charCode);
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
<input type="text" onkeyup="return isNumber(event);">