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.
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.
Share Improve this question edited Nov 12, 2017 at 7:42 Callat 3,0445 gold badges33 silver badges49 bronze badges asked Aug 6, 2013 at 5:50 Java QuestionsJava Questions 7,95343 gold badges119 silver badges177 bronze badges 2 |2 Answers
Reset to default 13Use 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?
min: 1
rule. – Barmar Commented Aug 6, 2013 at 6:15