简体   繁体   中英

Syntax error: missing : after property (jQuery validate)

I am building a set of jQuery validate rules to be used for a form prototype.

I am getting a JS error with my code. Chromes complains with the error

[14:30:27.722] SyntaxError: missing : after property id

at the location specified in the code comments.

here is the code:

    $.validator.addMethod("regex", function(value, element, regexpr) {          
        return regexpr.test(value);
    }, "Entree invalide");

    $('#mainform').validate({
        rules: {
            form-nocivique: { //Chrome complains here
                required: true,
                digits: true
            },
            form-rue: "required",
            form-province: "required",
            form-codepostal: {
                required: true,
                regex: /([ABCEGHJKLMNPRSTVWXYZ]\d){3}/i
            }
        },
    });

Any idea why?

Your property names (some of them) are invalid identifiers.

You can quote it to fix the problem:

   rules: {
        "form-nocivique": { //Chrome complains here
            required: true,
            digits: true
        },

You can't use - in an identifier in JavaScript; it's a token (the "minus" operator).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM