我正在使用 FormValidator.net 中的formValidator
,我的情况是需要验证密码和比较密码字段,根据插件,我们可以这样做。
<p>
Password (at least 8 characters)
<input name="pass_confirmation" data-validation="length" data-validation-length="min8"/>
Confirm password
<input name="pass" data-validation="confirmation"/>
</p>
由于我正在使用他们最新版本的插件,我也尝试了他们建议的如何做最新版本&gt; 2.2.1
如下:
<p>
Password (at least 8 characters)
<input name="pass_confirmation" data-validation="length" data-validation-length="min8"/>
Confirm password
<input name="pass" data-validation="confirmation" data-validation-confirm="pass_confirmation"/>
</p>
但它仍然没有比较密码。虽然我可以说password
的最小值比较正确发生。有没有人在这个插件上工作过。还有其他办法吗?
$.validate({
form: "#frmSample",
validateOnBlur: true, // enable validation when input looses focus
scrollToTopOnError: true, // Set this property to true if you have a long form
borderColorOnError: "rgb(167, 3, 0)",
borderColorOnSuccess: "#a94442",
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.2.43/jquery.form-validator.min.js"></script>
<form id="frmSample">
<p>
Password (at least 8 characters)
<input name="pass_confirmation" data-validation="length" data-validation-length="min8">
<br/>
Confirm password
<input name="pass" data-validation="confirmation">
</p>
</form>
答案 0 :(得分:2)
您必须加载安全模块。
将$.validate({options})
更改为$.validate({modules:'security', options})
在您的示例中,您的代码将如下所示:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.2.43/jquery.form-validator.min.js"></script>
<form id="frmSample">
<p>
Password (at least 8 characters)
<input name="pass_confirmation" data-validation="length" data-validation-length="min8">
<br/>
Confirm password
<input name="pass" data-validation="confirmation">
</p>
</form>
$.validate({
modules : 'security',
form: "#frmSample",
validateOnBlur: true, // enable validation when input looses focus
scrollToTopOnError: true, // Set this property to true if you have a long form
borderColorOnError: "rgb(167, 3, 0)",
borderColorOnSuccess: "#a94442",
});
查看工作fiddle
您必须使用模块&#39; security&#39;因为表单验证器插件是使用单独的模块创建的,例如。 &#39; location,file,swedish,uk&#39;你必须加载所需的模块。如果你想使用&#39; uk&#39;模块你必须使用modules:'uk'
等等。