Onkeypress, javascript is not validating special character -
javascript function avoid special characters. working expected alpha & numbers.only problem is, when need include -,. (k >= 188 && k <= 190) - not working. doing wrong?
var k; document.all ? k = e.keycode : k = e.which; return ((k > 64 && k < 91) || (k > 96 && k < 123) || (k >= 188 && k <= 190)|| k == 8 || k == 32 || (k >= 48 && k <= 57));
this latest code,it support browser. function isalphanumeric(evtget) {
var browser = navigator.appname; if (browser == "microsoft internet explorer" || browser == "mozilla firefox") { var keyget = evtget.keycode; } else { var keyget = evtget.which; //(window.event) ? evtget.which : evtget.keycode; } alert(keyget); if ((keyget > 47 && keyget < 58) || (keyget > 64 && keyget < 91) || (keyget > 96 && keyget < 123) || (keyget == 9) || (keyget == 32) || (keyget == 8) || (keyget == 0) || (keyget == 13)||(keyget==110)) return; else if (browser == "microsoft internet explorer" || browser == "mozilla firefox") window.event.returnvalue = null; else evtget.preventdefault(); }
put above code in header of jsp
and call input field onkeypress="return isalphanumeric(event,this.value);">
suppose want change in code per requirement,there alert box please run code 1st click on key board show keycode per requirement
example-you want enter (.)in field show keycode dot id 47 , can write (keyget==47)
Comments
Post a Comment