Users are allowed to add as many inputs as they want, where the input fields look like this:
<input id="minAge[0]"...
<input id="maxAge[0]"...
<input id="minAge[1]"...
<input id="maxAge[1]"...
<input id="minAge[2]"...
<input id="maxAge[2]"... etc
Problem
I want to validate for each pair of inputs (minAge[i],maxAge[i]) that the maxAge is greater than minAge.
Specific solution
$.validator.addMethod('lessThan', function(value, element, param) {
if (this.optional(element)) return true;
var i = parseInt(value);
var j = parseInt($(param).val());
return i < j;
}, "MinAge must be less than MaxAge");
$('#form').validate({
rules: {
minAge: {
lessThan: '#maxAge'
}
});
How can I make this solution generic?