1

formValidatorFormValidator.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>

4

1 回答 1

2

您必须加载安全模块。

更改$.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",
});

见工作小提琴


更新

您必须使用模块“安全”,因为表单验证器插件是使用单独的模块创建的,例如。“位置,文件,瑞典语,英国”,您必须加载所需的模块。如果你想使用'uk'模块,你必须使用modules:'uk'等等。

于 2015-09-02T08:37:50.537 回答