Regular Expression for Alphanumeric using Javascript

Chikul
Posted by Chikul under JavaScript category on | Views : 3878

Regular Expression for Alphanumeric using Javascript. You can use Javascripts to validate this as followes.
Define the Function "isNumberEvt" on Head Section. and check it on keypress even of text box like "onkeypress="return isNumberEvt(event)"".

Code :

<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function isNumberEvt(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode

if ((charCode > 31 && charCode < 48 ) || (charCode > 57 && charCode < 65 ) || (charCode > 90 && charCode < 97) || (charCode > 122))
return false;

return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="238px" onkeypress="return isNumberEvt(event)"></asp:TextBox></div>
</form>
</body>

Comments or Responses

Posted by: Santosh4u on: 12/23/2009 Level:Bronze | Status: [Member]
very helpful code.
thanx Chiku..P

Login to post response