<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <style type="text/css"> body { font-size: 9pt; font-family: Arial; } </style> </head> <body> Alphanumeric value: <input type="text" id="text1" /> <span id="error" style="color: Red; display: none">* Special Characters not allowed</span> <script type="text/javascript"> var specialKeys = new Array(); specialKeys.push(8); //Backspace specialKeys.push(9); //Tab specialKeys.push(46); //Delete specialKeys.push(36); //Home specialKeys.push(35); //End specialKeys.push(37); //Left specialKeys.push(39); //Right specialKeys.push(92); //\| function IsAlphaNumeric(e) { var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode; var ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode)); document.getElementById("error").style.display = ret ? "none" : "inline"; return ret; } </script> </body> </html>
<body> <input type="text" onkeypress="return IsAlphaNumeric(event);" id="text1" /> <b id="error" style="display:none; color:red">Invalid</b> </body>
event.preventDefault
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)