我有一个密码字段,我希望确保用户输入的密码符合下述条件: -
我尝试使用data-parsley-pattern和data-parsley-type但没有获得所需的结果。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/parsley.js/2.6.0/parsley.js"></script>
<form data-parsley-validate>
<input type="password" name="password" id="password" minlength="6" data-parsley-type="alphanum" data-parsley-pattern="^/^[a-zA-Z0-9\-\_]$/" class="form-control allForms" required data-parsley-required-message="Your password" data-parsley-trigger="change focusin" placeholder="Enter password">
</form>
答案 0 :(得分:3)
我认为,为了提高效率和可维护性,您应该定义一个自定义验证器,如解释here或正则验证器,如果您擅长它(((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?(?=.*[#%@!*(()+=]))).{6,16}
可以完成这项工作?); )
答案 1 :(得分:1)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/parsley.js/2.6.0/parsley.js"></script>
<form data-parsley-validate>
<input type="password" name="password" id="password" minlength="6" data-parsley-type="alphanum" data-parsley-pattern="^/^[a-zA-Z0-9\-\_]$/" class="form-control allForms" required data-parsley-required-message="Your password" data-parsley-trigger="change focusin" placeholder="Enter password">
</form>