I am using the jquery validation plugin for form validation. Using the min property works fine, but I want it to validate values strictly greater than that min value.
rules: {
price: {
required: true,
min: 13,
number: true
}
}
In my code I have min: 13, but I don’t want to allow 13, only values greater than 13, e.g. 13.10, 13.20, 14. How can I do this?
Thanks in advance !
Create your own custom method with
$.validator.addMethod:Then use:
Note: The creators of the validator plugin recommend adding
Number.MIN_VALUEto the value you supply:Number.MIN_VALUEis the smallest positive (non-zero) float that JS can handle, hence the logic is that the two statements below are equivalent:But, this doesn’t work, due to the way floating-point numbers are stored in memory. Rounding will cause
b + Number.MIN_VALUEto equalbin most cases (bmust be very small for this to work).