0

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

},
4

2 回答 2

2

破折号是变量名的非法字符,它将被解释为减号。您必须将确认电子邮件更改为确认电子邮件或其他内容。

于 2013-09-06T12:20:57.183 回答
0

目前接受的答案只对了一半。是的,破折号、-方括号、[]点或点等字符.将成为此插件的问题。但是,您不需要更改confirm-emailconfirm_email或其他。

您只需将名称括在引号中。

rules: {
    'confirm-email':  {
        required: true,
        equalTo: "#email"
     }
}

请参阅文档“通用指南”页面上的“具有复杂名称(括号、点)的字段”部分

工作演示:http: //jsfiddle.net/Zaf8N/

于 2013-09-06T16:39:38.507 回答