我正在使用JQuery验证来验证填写了两个字段,并且它们匹配。
$("#resetFormDo").validate({
rules: {
password: {
required: true
},
passwordCopy: {
required: true,
equalTo: '#password'
},
},
messages: {
password: "Both fields required",
passwordCopy: "Both fields required"
},
});
问题:如何在字段不匹配时添加其他错误消息?
如上所述,如果它为空或与其他密码字段不匹配,则只为passwordCopy字段提供相同的错误消息。我是否只需要使消息更通用,例如"两个字段都必须且必须匹配"?或者,有没有办法将它们分开?
答案 0 :(得分:2)
我认为这会解决它:
$("#resetFormDo").validate({
rules: {
password: {
required: true,
},
passwordCopy: {
required: true,
equalTo: "#password"
}
},
messages: {
password: {
required: "Please provide a password",
},
passwordCopy: {
required: "Please provide a password",
equalTo: "Both fields must match"
}
}
});
});