admin管理员组

文章数量:1387325

I have a little problem with jquery validation. In IE 6 and maybee in IE 7 i got an error message: Expected identifier....

I minimised my code and it seems, if i cut out the following part, then everything is works fine. Whats the problem?

I dont really understand where is the extra ma, so i decided i paste the hole validate script. Please take a look at my code.

jQuery.validator.addMethod("lettersonly", function(value, element) {
        return this.optional(element) || /^[a-zőöüóúéáűí ]+$/i.test(value);
}, "... betűket használjon");   

$("#test").validate({
    rules: {
        name: {
                required: true,
                minlength: 5,
                maxlength: 40,
                lettersonly: true
        },
        addr: {
                required: true,
                minlength: 15,
                maxlength: 80


        },
        phone: {
                required: true,
                minlength: 8,
                maxlength: 20,
                number: true         
        },
            email: {
                required: true,
                minlength: 5,
                email: true      
        },
        count: {
        required: true,
                minlength: 3,
                maxlength: 20,
                number: true         
        },
        nettoj: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        nettoj2: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        mini: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        mini2: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        adosj: {
                minlength: 3,
                maxlength: 20,
                number: true         
        },
        amini: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        stil: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        tcount: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        city: {
                minlength: 3,
                maxlength: 60,
                lettersonly: true        
        },


    },
    messages: {
        name: {
                required: "... !",
                minlength: "Minimum 5 ",
                maxlength: "Maximum 40 "
        },
        addr: {
                required: "... ",
                minlength: "Minimum 15 ",
                maxlength: "Maximum 80 "
        },
        phone: {
                required: "... ",
                minlength: "Minimum 8 ",
                maxlength: "Maximum 20 ",
                number: "... "

        },

        email: {
                required: "... e-mail ",
                minlength: "Minimum 5 ",
                email: "..."

        },
        count: {
                required: "... ",
                minlength: "Minimum 3 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
            nettoj: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
            nettoj2: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                mini: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                mini2: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                adosj: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                amini: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
            number: "... "

        },
                stil: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                tcount: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                city: {
                minlength: "Minimum 3 ",
                maxlength: "Maximum 80 "
        },

    },



   });  

I have a little problem with jquery validation. In IE 6 and maybee in IE 7 i got an error message: Expected identifier....

I minimised my code and it seems, if i cut out the following part, then everything is works fine. Whats the problem?

I dont really understand where is the extra ma, so i decided i paste the hole validate script. Please take a look at my code.

jQuery.validator.addMethod("lettersonly", function(value, element) {
        return this.optional(element) || /^[a-zőöüóúéáűí ]+$/i.test(value);
}, "... betűket használjon");   

$("#test").validate({
    rules: {
        name: {
                required: true,
                minlength: 5,
                maxlength: 40,
                lettersonly: true
        },
        addr: {
                required: true,
                minlength: 15,
                maxlength: 80


        },
        phone: {
                required: true,
                minlength: 8,
                maxlength: 20,
                number: true         
        },
            email: {
                required: true,
                minlength: 5,
                email: true      
        },
        count: {
        required: true,
                minlength: 3,
                maxlength: 20,
                number: true         
        },
        nettoj: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        nettoj2: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        mini: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        mini2: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        adosj: {
                minlength: 3,
                maxlength: 20,
                number: true         
        },
        amini: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        stil: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        tcount: {
                minlength: 2,
                maxlength: 20,
                number: true         
        },
        city: {
                minlength: 3,
                maxlength: 60,
                lettersonly: true        
        },


    },
    messages: {
        name: {
                required: "... !",
                minlength: "Minimum 5 ",
                maxlength: "Maximum 40 "
        },
        addr: {
                required: "... ",
                minlength: "Minimum 15 ",
                maxlength: "Maximum 80 "
        },
        phone: {
                required: "... ",
                minlength: "Minimum 8 ",
                maxlength: "Maximum 20 ",
                number: "... "

        },

        email: {
                required: "... e-mail ",
                minlength: "Minimum 5 ",
                email: "..."

        },
        count: {
                required: "... ",
                minlength: "Minimum 3 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
            nettoj: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
            nettoj2: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                mini: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                mini2: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                adosj: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                amini: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
            number: "... "

        },
                stil: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                tcount: {
                minlength: "Minimum 2 ",
                maxlength: "Maximum 20 ",
                                number: "... "

        },
                city: {
                minlength: "Minimum 3 ",
                maxlength: "Maximum 80 "
        },

    },



   });  
Share Improve this question edited Sep 24, 2010 at 17:25 holian asked Sep 23, 2010 at 21:33 holianholian 151 gold badge1 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

It's because you appended an extra ma to your object literal property, get rid of it

object = {
    property1: 23,
    property2: 14,
    property3: 42 //The answer, also, no ma after the 42, as it's the last
}                 //property of the object, if you have a ma here, then the
                  //javascript engine is expecting another member item to the
                  //object, and get's really peeved if you don't add it.

The reason minimizing the code worked was because it was really nice and got rid of those nasty extra mas which were annoying your javascript engine.

Edit

You still have extra mas in you new code in between nesting levels

    city: {                    //Look, it's the last member of an object
            minlength: 3,
            maxlength: 60,
            lettersonly: true        
    }, //<-- WHAT IS THAT COMMA DOING THERE!!!!!!!!!!!!!!!

/*At this point, parser is like, wtf, where's the next member?*/},

Remove the last , at this piece of code.

old

addr: {
    required: "...",
    minlength: "...",
    maxlength: "..."
},

new

addr: {
    required: "...",
    minlength: "...",
    maxlength: "..."
}

本文标签: javascriptjquery validation error Expected identifierStringor numberStack Overflow