I am trying to specify some rules dynamically on a form. On this form I have three TextBox input (Text1, Text2, Text3) and a checkbox (Check1)
I shall configure the following rules:
-
Rule for
Text2: The field shall be a positive number with 2 decimal digits and it’s value shall be equal or greater thanText1 -
Rule for
Text3: The field shall be a number with 2 decimal digits. Moreover:a) The value of
Text3has to be equal to zero ifCheck1is selectedb) The value of
Text3must be smaller or equal toText1and smaller or equal toText2ifCheck1is not selected.
How can I express those rules within the jQuery Validation plugin? Any advice?
UPDATE:
This is the basic rule for (1). It misses the equal or greather part:
$('#Text2').rules('add', {
required: true,
min: 0.0,
number: true,
messages: {
required: 'Message 1',
min: 'Message 2',
number: 'Message 3'
}
});
You can make use of $.validator.addMethod..
for example,
the above method just check for decimal.
We can use this by adding the first parameter name in the class name such as
In your case, you need to check for whether the value is greater than text1, so we can do it as