I have multiple input boxes and I have to check whether the entered values are positive or negative using jquery Validator plugin.
It is basically doing some calculation based on the value entered in the first input box.
The value entered must be positive, if not I should throw an error message saying the value must be positive or greater than zero.
Use the min
rule to specify that the minimum value is 1.
$("#formid").validate({
rules: {
fieldname: {
min: 1
},
messages: {
fieldname: {
min: "Value must be greater than 0"
}
}
});
You can use regex for validating numeric value. Code given below. The function will return true if input box contains numeric value (negative or positive)
function checkNumericValue(num)
{
var objRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
return objRegExp.test(num);
}
For checking -ve value, follow the link How to check the value given is a positive or negative integer?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With