Let user to press alphanumeric key only

If you want to allow user to entry only alphanumeric data in text box, the following code can be helpful for you.

<script type="text/javascript">
function VinCheck(e)
{
    var keynum;
    var keychar;
    var charcheck;
    if(window.event) // IE
       keynum = e.keyCode;
    else if(e.which) // Netscape/Firefox/Opera
       keynum = e.which;
    keychar = String.fromCharCode(keynum);
    charcheck = /[a-zA-Z0-9]/;
    return charcheck.test(keychar);        
}
</script>

Please note that in order to use this script function, you have to use "onKeyPress" event in your <input> tag or in <asp:TextBox> tag.

Here is the HTML Code

        <asp:Label ID="Label1" runat="server" Text="You can type only alphabets and numeric characters, no other characters. Try it"></asp:Label>
        <br />
        <br />
        <asp:TextBox ID="TextBox1" MaxLength="17" onKeyPress="return VinCheck(event);" Width="156px"
            runat="server" />
            
You can type only alphabets and numeric characters, no other characters. Try it

No  Responses to "Let user to press alphanumeric key only"

Leave a Reply