Adds

Tuesday, 2 September 2014

Allow only number in C# TextBox using JavaScript


C# Control:

<asp:TextBox CssClass="form-control" ID="txtContactNumber" runat="server" onkeypress="return isNumber(event)"></asp:TextBox>

JavaScript:

function isNumber(evt) {
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                return false;
            }
            return true;
        }