在单个字段上覆盖2条消息[重复]

时间:2022-12-01 08:26:04

This question already has an answer here:

这个问题在这里已有答案:

I have the following jquery validate configuration:

我有以下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!"
            }
}

As you can see fields password and confirm_password have 2 restrictions.

如您所见,字段密码和confirm_password有2个限制。

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

Can you advise how to override both these messages ?

你能告诉我们如何覆盖这两条消息吗?

P.S.

When I write the following config:

当我写下面的配置时:

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

Even if my passwords has length equals 10 but different I see message too simple password

即使我的密码长度等于10但不同,我看到消息太简单了

1 个解决方案

#1


2  

Try this:

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

#1


2  

Try this:

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