问题
I am using the following validation on my form, as i have a email address field and confirm email address field i need some validation to make sure these two fields match, i currently have the following which is giving me the error message that it does not match even when it does, anyone know why this could be?
rules: {
'entry[email]': {
required: true,
email: true
},
'entry[confirm_email]': {
// required: true,
equalTo: "entry[email]"
},
},
messages: {
'entry[email]': {
required: ' Please enter a valid email address',
minlength: 'Not a valid email address'
},
'entry[confirm_email]': {
required: ' Please make sure email matches above',
minlength: 'Does not match above email address'
},
}
回答1:
Try this way
rules:{
pwd:{
required:true //First email section
},
pwd1:{
required:true,//Second email section
equalTo: "#same" //Use id of the first email text box here
}
},
messages:{
pwd1:{
equalTo: "Must be same as above email"
}
}
Working Example
回答2:
$('#email).validate({
...
rules: {
...
'entry[confirm_email]': {
equalTo: "entry[email]"
}
}
});
Here "entry[email]" should be the id of input element!!
来源:https://stackoverflow.com/questions/22758997/email-validation-using-jquery-emails-matching