1

Here is the code for controlling length of a numeric field before and after the decimal point...
Its working perfect. Is it possible to pass values instead of {0,4}, {0,2} as a string data.

$("#amount").on("keyup", function(){
    var valid = /^\d{0,4}(\.\d{0,2})?$/.test(this.value),
        val = this.value;

    if(!valid){
        console.log("Invalid input!");
        this.value = val.substring(0, val.length - 1);
    }
});
Mustofa Rizwan
  • 10,215
  • 2
  • 28
  • 43
Ranjith prasad
  • 111
  • 1
  • 2
  • 6

0 Answers0