Allow only alphabets in a textbox using javascript in asp.net

Category > ASP.NET || Published on : Wednesday, January 27, 2016 || Views: 8093 || Allow only alphabets in a textbox using java script


Introduction

Here Pawan Kumar will explain how to Allow only alphabets in a textbox using java script

Description

In previous post I have explained How to turn off submit button when it pressed in ASP.Net, Code Snippets - Sending SMS through ASP.NET, Cascading dropdown in ASP.NET using JQuery Http Handler, How to add current copyright year in ASP.NET, How to avoid a form from double submission using asp.net, Set max length of MultiLine TextBox in ASP.Net, and many more articles.

Now I will explain How to Allow only alphabets in a textbox using javascript in asp.net

So follow the steps to learn Allow only alphabets in a textbox using javascript in asp.net
 <html>
<head>
    <title>allwon only alphabets in textbox using JavaScript</title>
    <script language="Javascript" type="text/javascript">

        function onlyAlphabets(e, t) {
            try {
                if (window.event) {
                    var charCode = window.event.keyCode;
                }

                else if (e) {
                    var charCode = e.which;
                }

                else { return true; }

                if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
                    return true;
                else
                    return false;
            }

            catch (err) {
                alert(err.Description);
            }
        } 
    </script>
</head>
<body>
    <table align="center">
        <tr>
            <td>
                <input type="text" onkeypress="return onlyAlphabets(event,this);" />
            </td>
        </tr>
    </table>
</body>
</html>

 

Conclusion:

So, In this tutorial we have learned, Allow only alphabets in a textbox using javascript in asp.net