Sunday, September 15, 2013

How to make a textbox numeric only using jquery

Firstly declare a input textbox & then applying the following regex on the keyup event of textbox like this:

<input type="text" name="txtSalary" id="txtSalary" />

 $('#txtSalary').keyup(function (e) {
        if (/\D/g.test(this.value)) {
            // Filter non-digits from input value.
            this.value = this.value.replace(/\D/g, '');
        }
    });

No comments:

Post a Comment