Jquery验证插件更改默认消息

时间:2017-11-16 06:48:12

标签: javascript jquery

如何在Jquery验证插件中更改默认的require消息。我尝试了以下内容,但仍然会打印默认消息:

$("#form1").validate({
        ignore: [],
        debug: false,
        rules: {
            firstName: {
                required: true,
                minlength: 2,
                maxlength: 200
            }
            message: {
                firstName:{
                    required: "Custom error message."
                }
            }
        }
    });
});

更新

我将消息更改为消息

 messages: {
             firstName:"Custom error message."
}

1 个答案:

答案 0 :(得分:2)

$("#form1").validate({
    ignore: [],
    debug: false,
    rules: {
        firstName: {
            required: true,
            minlength: 2,
            maxlength: 200
        },
        messages: {
            firstName:{
                required: "Firstname required",
                minlength: "Min length is 2",
                maxlength: "Max length is 200",
            }
        }
    }
});