Reputation: 4302
Iam using the jQuery validate library to validate a form. For some reason it is erroring when I trying to add confirm-email. The error is Unexpected token -
The id is correct in the HTML.
var validation_options = {
focusInvalid: false,
rules: {
name: { required: true },
houseno: { required: true },
streetname: { required: true },
postcode: { required: true, postcodeUK: true },
country: { required: true },
phone: { required: true, validPhone: true },
email: { required: true, email: true, unique: true },
confirm-email: { required: true, equalTo: "#email" }
},
messages: {
name: "Please enter your name",
houseno: {
required: "Please enter your house number",
},
streetname: "Please enter your street name",
postcode: {
required: "Please enter your postcode",
postcodeUK: "Please enter a valid postcode"
},
country: "Please enter your country",
phone: {
required: "Please enter your mobile number",
validPhone: "Please enter a valid phone number"
},
email: {
required: "Please enter your email",
email: "Please enter a valid email address",
unique: "This email has already been used"
},
confirm-email: {
required: "Please enter your email"
}
},
Upvotes: 0
Views: 251
Reputation: 98728
The currently accepted answer is only half correct. Yes, characters such as a dash, -
, brackets, []
, or a dot, .
will be a problem for this plugin. However, you are not required to change confirm-email
into confirm_email
or something else.
You simply need to enclose the name in quotes.
rules: {
'confirm-email': {
required: true,
equalTo: "#email"
}
}
Working Demo: http://jsfiddle.net/Zaf8N/
Upvotes: 0
Reputation: 3624
The dash is an illegal character for a variable name, it will get interpreted as a minus sign. You'll have to change confirm-email to confirm_email or something.
Upvotes: 2