Your current
isNumberKey
function will not work as you expect it to. It currently only rejects character
46
(
Delete), which is one of the characters you should be allowing.
function isNumberKey(event){
var charCode = event.which || event.keyCode;
switch (charCode) {
case 8:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 46: {
return true;
}
default: {
if (48 <= charCode && charCode <= 57) {
return true;
}
return false;
}
}
}
Javascript key codes | CSS-Tricks[
^]
You should be using the built-in support in modern browsers:
HTML Input Types[
^]
<input type="number" min="5" max="100" ... />
That has fairly decent browser support:
Can I use... Number input type[
^]
Then, as mentioned in the comments, use the
jQuery Validation Plugin[
^] to validate your input.