I have an e-mail field, and a confirm e-mail field. I need to validate both of them开发者_JAVA百科 to make sure their values match.
Is there a way to add a rule to match those two fields?
You could use the equalTo method:
$('#myform').validate({
rules: {
email: 'required',
emailConfirm: {
equalTo: '#email'
}
}
});
You can also do this on the second field:
class="required email" equalTo='#email'
U can use this
email: {
required: true, email: true
},
c_email: {
required: true, equalTo: "#email", minlength: 5
},
<div class="form-row"><span class="label">email</span><input type="email" name="email" class="required" id="email" /></div>
<div class="form-row"><span class="label">Confirm email</span><input type="email" name="c_email" id="c_email" /></div>
精彩评论