Return to Snippet

Revision: 62115
at February 2, 2013 02:49 by jprochazka


Initial Code
<html>
<head>
<script type="text/javascript">
    function checkIt(evt) {
        evt = (evt) ? evt : window.event
        var charCode = (evt.which) ? evt.which : evt.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            document.getElementById("errorMessage").innerHTML = "This field accepts numbers only."
            return false
        }
        document.getElementById("errorMessage").innerHTML = ""
        return true
    }
</script>
</head>
<body>
    <input id="numbersOnly" type="text" onKeyPress="return checkIt(event)" />
    <span id="errorMessage"></span>
</body>
</html>

Initial URL

                                

Initial Description
The following code allows only numeric characters to be entered.

Initial Title
Allow only numberic key presses.

Initial Tags
validation

Initial Language
JavaScript