I have price field and i have code to validate price field.
$("#price").inputFilter(function(value) {
return /^-?\d*[.,]?\d{0,2}$/.test(value);
});
from above code after "." only 2 digit can enter in input field. but i need to validate max integer to 4. ie. 2555.23
CodePudding user response:
Assuming you only want to allow for prices which are strictly less than 10,000 you may use ^-?\d{1,4}(?:\.\d{2})?$
. Your updated code:
$("#price").inputFilter(function(value) {
return /^-?\d{1,4}(?:\.\d{2})?$/.test(value);
});