The purpose of this JAVSCRIPT function is to prevent users from entering any alpha characters. If user enters those characters, the cursor does not move at all and stays at the same place. However if user enters a digit, cursor moves to the next position.
For example, in this text field, I only allow users to enter digits only. This method is working fine in all browsers except IE 8 and earlier. I tested it on Firefox, Chrome, and Safari and even in Safari emulator with no issues. If anybody guide me or even suggest me to modify my method so that it also works fine in IE that would be great help!!! Thank you
function AllowOnlyDigit(e) {
var ev = e || window.event;
var key = ev.keyCode || ev.which || ev.charCode;
if (key > 31 && (key < 48 || key > 57)) {
return false;
}
return true;
}
and this is how I am invoking this method :
<input type="text" onkeypress="return AllowOnlyDigit(event)" />