views:

109

answers:

3

Hi Gods,

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 comma, 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 "
        },

    },



   });  
+1  A: 

Remove the last , at this piece of code.

old

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

new

addr: {
    required: "...",
    minlength: "...",
    maxlength: "..."
}
gearsdigital
please take a look at my code, i pasted the hole script 'coz i dont really find the extra comma...thank you
holian
+2  A: 

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

object = {
    property1: 23,
    property2: 14,
    property3: 42 //The answer, also, no comma after the 42, as it's the last
}                 //property of the object, if you have a comma 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 commas which were annoying your javascript engine.

Edit

You still have extra commas 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?*/},
Andrew Dunn
please take a look at my code, i pasted the hole script 'coz i dont really find the extra comma...thank you
holian
@hollan you might want to look again. You have 3 or 4 extra commas. (one at the end of each property list)
indieinvader
ehh..you mess me up...so i have to do this? stil: { minlength: "Minimum 2 ", maxlength: "Maximum 20 ", number: "... " }, // <<<--- that is the extra comma?
holian
i got it...thank you very much
holian