Reputation: 3697
I am using the plugin from here: http://bassistance.de/jquery-plugins/jquery-plugin-validation/
and I am wondering if anyone has any code that will allow me to compare 2 form fields and validate that field_1
must be larger than field_2
?
I am initiated the validate method like:
$("#frmValidate").validate({
meta: "validate"
});
Many thanks.
Upvotes: 0
Views: 505
Reputation: 1196
You need to declare the validation method, something like that:
$.validator.addMethod(
"greaterThan",
function(value,element,params) {
if (value > $(params).val()) {
return true;
}
return false;
},
"Wrong"
);
And then use it in validation.
$('#my_form').validate({
rules: {
'field1': {
required: true,
greaterThan: '#field2'
}
}
});
Upvotes: 2
Reputation: 33318
This can be done in a simple two-step process:
Upvotes: 0