I'm using jQuery Validate Plugin: http://bassistance.de/jquery-plugins/jquery-plugin-validation/
Simple demo:
<input type="text" name="email" class="required email" />
<input type="text" name="email_confirm" class="required email" />
How to check if the value in the two inputs are the same with jQuery or with jQuery Validate Plugin.
I just tried equalto
and it works:
rules: { email: 'required', email2: {equalTo: '.email'}
By looking at the demo page at http://jquery.bassistance.de/validate/demo/ you can validate 2 fields that should be equal by using "equalTo":
$("#signupForm").validate({
rules: {
...snip...
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
},
...snip...
},
messages: {
...snip...
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
confirm_password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
},
...snip...
}
});
To do it using the class method, you just need to find the syntax. I couldn't find it for the equalTo attribute, but it is probably something like:
class="required email equalTo['email']"
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