在单个字段上覆盖2条消息

时间:2015-07-20 21:11:58

标签: jquery jquery-validate

我有以下jquery验证配置:

$('form[name=register_form]').validate({
            rules: {
                email: {
                    required: true,
                    email: true
                },
                password: {
                    minlength: 3,
                    maxlength: 15
                },
                confirm_password: {
                    minlength: 3,
                    maxlength: 15,
                    equalTo:"#password"
                }
            },
            messages: {
                email: "You should input real email adress!"
            }
}

正如您所见,字段passwordconfirm_password有2个限制。

1. length 3 -15  
2. Its should be equal.

您能否建议如何覆盖这两条消息?

P.S。

当我写下面的配置时:

 messages: {
                email: "invalid email",
                password: "too simple password",
                confirm_password: "too simple password",
                equalTo: "wrong password confirmation"
            }

即使我的密码长度等于10但不同,我也会看到消息too simple password

1 个答案:

答案 0 :(得分:2)

试试这个:

messages: {
    password: {
        minlength: 'Your password must be at least 3 characters long',
        maxlength: 'Your password cannot exceed 15 characters',
        equalTo: "wrong password confirmation"
    }
}