[英]Form validation error - equalTo
Iam using the jQuery validate library to validate a form. 我使用jQuery验证库来验证表单。 For some reason it is erroring when I trying to add confirm-email.
出于某种原因,当我尝试添加confirm-email时出错。 The error is Unexpected token -
错误是意外的令牌 -
The id is correct in the HTML. HTML中的id是正确的。
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"
}
},
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.
您必须将confirm-email更改为confirm_email或其他内容。
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. 但是,你是不是需要更改
confirm-email
到confirm_email
或别的东西。
You simply need to enclose the name in quotes. 您只需将名称括在引号中即可。
rules: {
'confirm-email': {
required: true,
equalTo: "#email"
}
}
See the "Fields with complex names (brackets, dots)" section on the "General Guidelines" page of the documentation . 请参阅文档“一般准则”页面上的“ 具有复杂名称(括号,点)的字段”部分 。
Working Demo : http://jsfiddle.net/Zaf8N/ 工作演示 : http : //jsfiddle.net/Zaf8N/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.