我使用formValidator
从FormValidator.net和我有一个情况,我需要验证密码和比较密码字段,根据插件这是我们如何做到的。
<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>
,因为我使用的是他们最新版本的插件,我也尝试了他们建议的最新版本> 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>
必须加载安全模块。
将$.validate({options})
改为$.validate({modules:'security', options})
在您的示例中,您的代码看起来像:
HTML
<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>
JavaScript $.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",
});
查看工作小提琴
更新
你必须使用模块'security',因为表单验证器插件是用单独的模块创建的。'位置,文件,瑞典,英国',你必须加载所需的模块。如果你想使用'uk'模块,你必须使用modules:'uk'
等等。