Allow only Numeric values in ASP.net Text box control using JavaScript

<script language="javascript" type="text/javascript">
        function onlyNumbers(evt) {
            var e = event || evt;
            var charCode = e.which || e.keyCode;

            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;

            return true;

        }
    </script>


<asp:TextBox ID="txt" runat="server" MaxLength="3" onkeypress="return onlyNumbers();"></asp:TextBox>

Comments

Post a Comment