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

3 Comments | 859 Views | Post by: Admin | Tags: Allow only alphabets in a textbox using java script


Allow only alphabets in a textbox using javascript


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


Post Comments

if you have some suggestion, question, request on Allow only alphabets in a textbox using javascript in asp.net.

Please use the comment box to express your views.

 

Comments:

loading...