Click here to Skip to main content
14,832,124 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

1 solution

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" />

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