Friday, February 20, 2009

JavaScript Validation: Alphanumeric and underscore only


//add this to textbox :onkeypress="validate(event);"
// validates and don't allow typing characters other than a-z,A-Z, 0-9 and _
function validatePortalName(e)
{
if(window.event) // IE
keynum = e.keyCode;
else if(e.which) // Netscape/Firefox/Opera
keynum = e.which;
return ((keynum >= 97 && keynum <=122)(keynum >= 65 && keynum <=90)(keynum>=48 && keynum<=57) keynum==95);
}

Note: code is tested in ie7 and mozilla firefox 3.0.6. Please test in the borwser you target before using it in production. regards

1 comment:

  1. I found this site using [url=http://google.com]google.com[/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!

    Sorry for offtopic

    ReplyDelete

Please add your valuable comments about this post if it helped you. Thanks