Parsley js:密码字段(最小长度)的表单验证未按预期工作
Parsley js: Form validation for password field(minlength) not working as expected
我的 HTML 中有以下表格:
<form action="" method="POST" accept-charset="utf-8" data-parsley-validate >
<fieldset>
<legend>Parsely JS Testing</legend>
<input type="" name="Full Name" placeholder="Full Name" data-parsley-pattern="[a-z|A-Z]" data-parsley-trigger="focusin focusout" data-parsley-error-message="You need to enter your full name" data-parsley-errors-container="#error-container">
<input type="" name="Phone" placeholder="Phone" data-parsley-type="digits" data-parsley-min="10" data-parsley-trigger="focusin focusout" data-parsley-error-message="Enter valid phone number" data-parsley-errors-container="#error-container">
<input type="" name="Email" placeholder="Email" data-parsley-type="email" data-parsley-trigger="focusin focusout" data-parsley-error-message="Enter Valid Email" data-parsley-errors-container="#error-container">
<input type="" name="password" placeholder="Password" data-parsley-type="alphanum" data-parsley-min="7" data-parsley-trigger="focusin focusout" data-parsley-error-message="Password must be atleast 7 characters" data-parsley-errors-container="#error-container" id="password">
<input type="" name="confirmpassword" placeholder="Confirm Password" data-parsley-trigger="focusin focusout" data-parsley-error-message="Password Does not match" data-parsley-errors-container="#error-container" data-parsley-equalto="#password">
</fieldset>
<button type="submit">SUBMIT</button>
</form>
我正在使用 parsely.js 来验证此表单,我在验证密码字段时遇到了一个小问题。我有以下 HTML 密码字段:
<input type="" name="password" placeholder="Password" data-parsley-type="alphanum" data-parsley-min="7" data-parsley-trigger="focusin focusout" data-parsley-error-message="Password must be atleast 7 characters" data-parsley-errors-container="#error-container" id="password">
该字段在 focusin
和 focusout
上验证,如下所示:
data-parsley-trigger="focusin focusout"
为了验证,我有 2 个规则,如下:
data-parsley-type="alphanum"
和
data-parsley-min="7"
这两个规则似乎不能很好地协同工作,所以如果我输入以下密码:
gautam007
我在 #error-container
中得到一个错误,得到的错误是我在错误消息数据属性中输入的错误。
data-parsley-error-message="Password must be at least 7 characters"
为什么我会收到这个错误,我该如何解决这个问题?
试试看,而不是 data-parsley-min,
data-parsley-mincheck='7'
这里是 demo 您如何实施 minlength
验证和错误消息。
您需要在表单元素上使用这些 data attributes
:
data-parsley-minlength="7"
data-parsley-minlength-message="Name must be at least 7 characters"
示例:
<input type="text" id="name" name="name" data-parsley-minlength="7" data-parsley-minlength-message="Name must be at least 7 characters" data-parsley-required="true" />
我的 HTML 中有以下表格:
<form action="" method="POST" accept-charset="utf-8" data-parsley-validate >
<fieldset>
<legend>Parsely JS Testing</legend>
<input type="" name="Full Name" placeholder="Full Name" data-parsley-pattern="[a-z|A-Z]" data-parsley-trigger="focusin focusout" data-parsley-error-message="You need to enter your full name" data-parsley-errors-container="#error-container">
<input type="" name="Phone" placeholder="Phone" data-parsley-type="digits" data-parsley-min="10" data-parsley-trigger="focusin focusout" data-parsley-error-message="Enter valid phone number" data-parsley-errors-container="#error-container">
<input type="" name="Email" placeholder="Email" data-parsley-type="email" data-parsley-trigger="focusin focusout" data-parsley-error-message="Enter Valid Email" data-parsley-errors-container="#error-container">
<input type="" name="password" placeholder="Password" data-parsley-type="alphanum" data-parsley-min="7" data-parsley-trigger="focusin focusout" data-parsley-error-message="Password must be atleast 7 characters" data-parsley-errors-container="#error-container" id="password">
<input type="" name="confirmpassword" placeholder="Confirm Password" data-parsley-trigger="focusin focusout" data-parsley-error-message="Password Does not match" data-parsley-errors-container="#error-container" data-parsley-equalto="#password">
</fieldset>
<button type="submit">SUBMIT</button>
</form>
我正在使用 parsely.js 来验证此表单,我在验证密码字段时遇到了一个小问题。我有以下 HTML 密码字段:
<input type="" name="password" placeholder="Password" data-parsley-type="alphanum" data-parsley-min="7" data-parsley-trigger="focusin focusout" data-parsley-error-message="Password must be atleast 7 characters" data-parsley-errors-container="#error-container" id="password">
该字段在 focusin
和 focusout
上验证,如下所示:
data-parsley-trigger="focusin focusout"
为了验证,我有 2 个规则,如下:
data-parsley-type="alphanum"
和
data-parsley-min="7"
这两个规则似乎不能很好地协同工作,所以如果我输入以下密码:
gautam007
我在 #error-container
中得到一个错误,得到的错误是我在错误消息数据属性中输入的错误。
data-parsley-error-message="Password must be at least 7 characters"
为什么我会收到这个错误,我该如何解决这个问题?
试试看,而不是 data-parsley-min,
data-parsley-mincheck='7'
这里是 demo 您如何实施 minlength
验证和错误消息。
您需要在表单元素上使用这些 data attributes
:
data-parsley-minlength="7"
data-parsley-minlength-message="Name must be at least 7 characters"
示例:
<input type="text" id="name" name="name" data-parsley-minlength="7" data-parsley-minlength-message="Name must be at least 7 characters" data-parsley-required="true" />