Wednesday 2 January 2013

JQuery Input text box Numeric Validation Integer and Decimal



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


///////////////////////////////////////Decimal Validation ///////////////////////////////////////////////////////
            $("#txtRequestedDays").keyup(function () {
                if (this.value != this.value.replace(/[^0-9\.]/g, '')) {
                    this.value = this.value.replace(/[^0-9\.]/g, '');
                }
            });


6 comments:

  1. nah flickerring aka user shows the char then disappear!

    use something like :
    $("#oCAUSE_goal, #oCAUSE_goalnow").keypress(function(e) {
    if (!(e.keyCode >= 48 && e.keyCode <= 57))
    e.preventDefault();
    });

    for integer input

    ReplyDelete
  2. Thanks for this post.

    ReplyDelete