Can we get the jQuery Validate error type?

*爱你&永不变心* 提交于 2019-12-24 03:12:12

问题


I am using the jQuery Validation Plugin. Is there any way to get the type of error from the jQuery form validation? For example,

$('registration-form').validate({
    rules: {
        email: {
            required: true,
            email: true
        }
    },
    messages: {
        email: {
            required: "This is a required field.",
            email: "This is not a valid email address"
        }
    },
    errorPlacement: function(error, element) {
        error.appendTo(element.parent());
    }
});

I would like to place only the error message generated from a "required" error inside a "div" somewhere on the html page rather than appending it to "element.parent()". If I can get the error type, e.g. "required" or "email" error, I can write the code to do this.

Any help is appreciated! Thanks!

aobs


回答1:


You may edit plugin easily. You can add one more parameter for each validation(see the regexes) to identify which one is caught.



来源:https://stackoverflow.com/questions/12075804/can-we-get-the-jquery-validate-error-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!