Menu ▼

Previous Next

Allow only alphabets in a textbox using javascript :

Example:
-------------


Code Sample :

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

Previous Next




Search dotnetlearners.com