Reputation: 829
I have a textbox, I need to validate my textbox using onkeypress
(to restrict special characters). It works fine in Chrome. In Mozilla Firefox it does not fire (Tab Button). Is there any events to add in my code?
My code:
function alpha(e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 9); //k=9(keycode for tab)
}
Upvotes: 0
Views: 672
Reputation: 1296
This might help you.
function alpha(e){
var k = e.charCode ? e.charCode : e.keyCode;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 9); //k=9(keycode for tab)
}
Upvotes: 1
Reputation: 7525
test this code
function alpha(e) {
var code = e.keyCode || e.which;
if(code == 9) { //Tab keycode
//Do something
}
}
Upvotes: 1