JQuery 验证 - 太多递归 - 堆栈溢出
JQuery validate - too much recursion - stack overflow
我正在使用 JQuery 验证插件并出现太多递归错误,我不知道为什么。
Here's a fiddle to show the error (you can see it in firebug)
要测试:在第一个字段中输入 "john@hotmailcom",然后跳出并查看错误消息,然后单击返回并将其更改为 "john@hotmail.com" 并再次跳出
这里是JQ:
// ensure password contains at least one number and one letter
$.validator.addMethod("passwordRegex", function(value, element) {
return this.optional(element) || /[a-z].*[0-9]|[0-9].*[a-z]/i.test(value);
}, "Password must contain letters & numbers");
$("#groupReg").validate({
errorElement: 'span',
errorClass: 'field-validation-error2',
rules: {
Email: {
required: true,
email: true
},
EmailConfirm: {
required: true,
email: true,
equalTo: Email
},
Password: {
required: true,
minlength: 6,
passwordRegex: "Password format not valid"
},
},
messages: {
Email: {
required: "to continue, please enter your email address",
email: "that's not a valid email address"
},
EmailConfirm: {
required: "to continue, please enter your email address again",
email: "that's not a valid email address",
equalTo: "Please ensure the email addresses match"
},
Password: {
required: "to continue, please enter a password using letters and numbers",
minlength: "Your password must be at least 6 characters long"
}
},
success: function() {
$( "#groupReg" ).submit();
},
});
知道哪里出了问题吗?
从 success
处理程序中删除对 submit()
的调用 - 可能还有整个 success
处理程序,如果这就是您使用它的全部目的。
当字段有效时使用该处理程序,按原样调用它会陷入无限循环。
我正在使用 JQuery 验证插件并出现太多递归错误,我不知道为什么。
Here's a fiddle to show the error (you can see it in firebug)
要测试:在第一个字段中输入 "john@hotmailcom",然后跳出并查看错误消息,然后单击返回并将其更改为 "john@hotmail.com" 并再次跳出
这里是JQ:
// ensure password contains at least one number and one letter
$.validator.addMethod("passwordRegex", function(value, element) {
return this.optional(element) || /[a-z].*[0-9]|[0-9].*[a-z]/i.test(value);
}, "Password must contain letters & numbers");
$("#groupReg").validate({
errorElement: 'span',
errorClass: 'field-validation-error2',
rules: {
Email: {
required: true,
email: true
},
EmailConfirm: {
required: true,
email: true,
equalTo: Email
},
Password: {
required: true,
minlength: 6,
passwordRegex: "Password format not valid"
},
},
messages: {
Email: {
required: "to continue, please enter your email address",
email: "that's not a valid email address"
},
EmailConfirm: {
required: "to continue, please enter your email address again",
email: "that's not a valid email address",
equalTo: "Please ensure the email addresses match"
},
Password: {
required: "to continue, please enter a password using letters and numbers",
minlength: "Your password must be at least 6 characters long"
}
},
success: function() {
$( "#groupReg" ).submit();
},
});
知道哪里出了问题吗?
从 success
处理程序中删除对 submit()
的调用 - 可能还有整个 success
处理程序,如果这就是您使用它的全部目的。
当字段有效时使用该处理程序,按原样调用它会陷入无限循环。