I Have this JavaScript code to allow only numeric input on textboxes
function CheckNumeric(e) {
if (window.event) // IE
{
if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8) {
event.returnValue = false;
return false;
}
}
else { // Fire Fox
if ((e.which < 48 || e.which > 57) & e.which != 8) {
e.preventDefault();
return false;
}
}
}
The problem is that it’s also preventing the "TAB" button! which I like to allow.
How can I do that?
I would change the
CheckNumericfunction into something like this and use a regex to determine valid/invalid input./[0-9\t\b]+/matches numbers, tabs and backspace. if you also want to allow space change it to/[0-9\t\b\s]+/additionally, in order to capture keycodes correctly you should bind to the
onKeyPressevent instead ofonKeyDownas it will not provide correct keycodes for the numeric keypad.