formvalidator.net 比较密码无效

formvalidator.net compare password not working

我正在使用来自 FormValidator.netformValidator,我遇到了需要验证 密码 的情况和比较密码字段,根据插件,我们可以这样做。

<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",
});

查看工作fiddle


更新

您必须使用模块 'security',因为表单验证器插件是使用单独的模块创建的,例如。 'location, file, swedish, uk' 并且您必须加载所需的模块。如果你想使用 'uk' 模块你必须使用 modules:'uk' 等等。