Thursday, February 10, 2011

Allowing only Numeric in web TextBox using JS

<script type = "text/javascript">
        function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && charCode != 46 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }
</script>


Call the isNumberKey(event) function on keypress event of the textbox like this:
<asp:TextBox id="txtQty"  runat="server" onkeypress="return isNumberKey(event);"/>

No comments:

Post a Comment