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);
}
});