我的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验证此表单,我在验证密码字段时遇到了一些问题。我有密码feild的以下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"
为什么我会收到此错误以及如何解决此问题?
答案 0 :(得分:1)
以下是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" />
答案 1 :(得分:0)
试试这个,看看而不是data-parsley-min,
data-parsley-mincheck='7'