[英]equalTo validation with jQuery Validate
Below is my form which has password and confirm password field 以下是我的具有密码和确认密码字段的表格
<div class="form-group">
<label class="control-label">password</label>
<input type="text" class="form-control" name="password"
data-validate="minlength[8]"
data-message-required="email is required" placeholder="password">
</div>
<div class="form-group">
<label class="control-label">confirm password</label>
<input type="text" class="form-control" name="password_confirm"
data-validate="minlength[8],equalTo[password]"
data-message-required="email is required" placeholder="confirm password">
</div>
Below is my part of validation field. 以下是我验证字段的一部分。
if (params = rule.match(/(\w+)\[(.*?)\]/i)) {
if ($.inArray(params[1], ['minlength', 'equalTo']) != -1) {
opts['rules'][name][params[1]] = params[2];
message = $field.data('message-' + params[1]);
if (message) {
opts['messages'][name][params[1]] = message;
}
}
}
The minlength[8]
seems to work perfectly, but when i try to match my password
with confirm password its not working. minlength[8]
似乎工作正常,但是当我尝试将我的password
与确认密码匹配时无法正常工作。 I tried passing the name attribute in three ways, but none of them work. 我尝试通过三种方式传递name属性,但是它们都不起作用。
equalTo[password]
equalTo["password"]
equalTo["#password"]
Also can anyone tell me what does this regular expression do /(\\w+)\\[(.*?)\\]/i)
也有人可以告诉我这个正则表达式做什么
/(\\w+)\\[(.*?)\\]/i)
The parameter inside equalTo["#password"]
is #password
. equalTo["#password"]
内部的参数是#password
。
#password
is a jQuery selector that matches an element with id="password"
. #password
是一个与id="password"
匹配的jQuery选择器。 However, I don't see a id
attribute on your password
field. 但是,我在您的
password
字段上看不到id
属性。 Try adding one... 尝试添加一个...
<input type="text" class="form-control" id="password" name="password" ....
Quote OP : 引用OP :
"Also can anyone tell me what does this regular expression do
/(\\w+)\\[(.*?)\\]/i
"“还有谁能告诉我这个正则表达式
/(\\w+)\\[(.*?)\\]/i
”
See: http://regexr.com/39d43 请参阅: http : //regexr.com/39d43
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.