Click here to Skip to main content
15,888,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am working ASP.NET Application.I want to validate a TextBox using Javascript allows only alphapets and restrict numbers. Please give me clear idea with source code.

Thanks & Regards
S.Arun Kumar
Posted

1 solution

JavaScript
function CheckAlphabets(e) {

    var whichCode = 0;
    if (window.event)
        whichCode = window.event.keyCode
    else if (e)
        whichCode = e.which;

    if ((c>=65 && c<=90) || (c>=97 && c<=122) || (c==32)) {
        return true;
    }
    else {
        return false;
    }

}
<asp:TextBox ID="txtName" onKeyDown='javascript: return CheckAlphabets(event);' runat="server" />
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900