Jquery 验证模式方法停止验证其他字段

Jquery validate pattern method stops validation of other fields

我正在使用 Jquery Validate 插件以及其他方法来对我的表单进行客户端验证。到目前为止一切正常,我只有一个问题。当我使用其中一种附加方法对其进行验证时,如果该方法失败,则它不会继续验证任何其他字段。

所以目前我将表格留空并点击提交,我会看到所有错误的列表。但是,如果我在名称字段中输入数字并点击提交,那么我只会看到失败模式规则的一个错误。这是我的 jquery:

$j("#wizardForm").validate({
    rules: {
        firstname: {
            required: true,
            pattern: /^[a-zA-Z]+([\s]+)?[']?([a-zA-Z]+)?$/
        },
        lastname: {
            required: true,
            pattern: /^[a-zA-Z]+([\s]+)?[']?([a-zA-Z]+)?$/
        },
        email: {
            required: true,
            email: true
        },
        password: "required",
        PWconfirm: "required",
        country: "required"
    },
    errorLabelContainer: ".validation-error-msg",
    wrapper: "li",
    errorClass: "validation-error",
    messages: {
        firstname: {
            required: "The 'First Name' field cannot be empty.",
            pattern: "The first name field must only contain letters."
        },
        lastname: {
            required: "The 'Last Name' field cannot be empty.",
            pattern: "The 'Last Name' field must only contain letters."
        },
        email: {
            required: "The 'Email Address' field cannot be empty.",
            email: "The email address must be in a valid email format."
        },
        password: "The 'Password' field cannot be empty.",
        PWconfirm: "The 'Retype Password' field cannot be empty.",
        country: "The 'Country' field needs a valid selection."
    }
});

有没有一种方法可以让它在其他方法的规则失败时显示所有错误?

您的 wrapper 选项破坏了它。可能是因为您试图在 <ul> 容器之外创建 <li> 元素。阅读 the docs for wrapper...

Wrap error labels with the specified element. Useful in combination with errorLabelContainer to create a list of error messages.

但你并不是在创建 "list of error messages";您正在创建内联消息,因此 wrappererrorLabelContainer 在此演示中毫无意义。

否则工作:http://jsfiddle.net/07jm89wp/3/