jQuery validator - Cannot call method 'call' of undefined error - while adding validation dynamically

前端 未结 6 1679
失恋的感觉
失恋的感觉 2020-12-31 14:13

This is my code to update the jQuery validation dynamically. In document load i create the validation. This code is used to update the phone number validation dynamically. A

6条回答
  •  没有蜡笔的小新
    2020-12-31 14:33

    There are four potential problems.

    1) You're missing a closing brace for the messages section.

    $("#phone").rules("add", {
        required: true,
        phoneUS: true,
        messages: {
            required: "Enter company phone number",
            phoneUS: "Enter valid phone number"
        } //<-- this was missing 
    });
    

    DEMO: http://jsfiddle.net/A8HQU/2

    2) There is a known bug where adding messages using the rules('add') method breaks the plugin and/or rule. Make absolutely sure you are including jQuery Validate version 1.11.1 or better.

    3) The phoneUS rule requires the inclusion of the additional-methods.js file.

    4) The rules('add') method must come after the .validate() initialization function.

    Note:

    You're using the phoneUS rule, so minlength and maxlength are totally superfluous since the phoneUS rule is already looking for a precise format/length.

提交回复
热议问题