Escape dot in jquery validate plugin

667 views Asked by At

I'm using a jquery validation plugin as below

$( "#myform" ).validate({
    rules: {
        user.email: {         //the dot causes an error
            required: true,
            email: true
        }
    }
});

I have a dot in the name of the user email input text field name and this causes an error. How do I escape this dot? It's not in a String so I can't use \\

The Html element looks like this

<input type="text" name="user.email"/>

This is the plugin I'm using

1

There are 1 answers

1
pid On BEST ANSWER

You cannot escape it, you must quote it, like this:

"user.email": {

Truth is, it's a best practice to use double-quotes (NOT single-quotes!) for all keys even when you don't need the quotes. This is to uniform with JSON, which requires the double-quotes.