Hi All
I use the following script to stop users typing in anything but standard
chars (eg letters, numbers, etc) into a input textbox:
<!--
// 8 = backspace
// 9 = tab
// 46 = del
// 190 = period (full stop)
// >36 to <41 = 4 x arrow keys
// >47 to <58 = 0 to 9
// >64 to <91 = A to Z
// >95 to <106 = 0 to 9 on numeric keypad
function CheckCodeEntry(e) {
var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
var shiftcheck = (navigator.appName == "Netscape") ? e.SHIFT_MASK :
event.shiftKey;
if (shiftcheck) {
if (key == 8 || key == 9 ||
key == 46 || (key 36 && key < 41) ||
(key 63 && key < 74) || (key 64 && key < 91) ||
key == 189) {
return true;
}
else {
return false;
}
}
else {
if (key == 8 || key == 9 || key == 190 ||
key == 46 || (key 36 && key < 41) ||
(key 47 && key < 58) || (key 64 && key < 91) ||
(key 95 && key < 106) || key == 189) {
return true;
}
else {
return false;
}
}
}
//-->
The input box is set as follows:
<INPUT TYPE='TEXT' NAME='code' SIZE=30 onKeyDown='return
CheckCodeEntry(event)' onKeydown='return CheckCodeEntry(event)' VALUE="">
Although this appears to work fine in IE and Netscape, Safari and Firefox
only allows me to enter letters. They don't allow me to enter numbers.
Could you please advise as to what I'm doing wrong.
Thanks
Laphan