JQuery验证 - 过多的递归 - 堆栈溢出

时间:2015-01-26 14:12:14

标签: javascript jquery jquery-validate

我正在使用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();
    },
    });

知道什么是错的吗?

1 个答案:

答案 0 :(得分:2)

submit()处理程序中移除对success的调用 - 可能还有整个success处理程序,如果这就是您使用它的全部内容。

当一个字段生效时使用该处理程序,因为你正在以无限循环结束调用它。