Enforce strong password policy with parsley.js

好久不见. 提交于 2019-12-11 23:45:16

问题


I have a password field that i will like to ensure that the users input a password that will meet the criteria stated below:-

  1. Must contain at least one capital letter
  2. Must contain at least one small letter
  3. Must contain a number and lastly
  4. A special character like #%@!*(()+= ( optional )

I have tried to use the data-parsley-pattern, and data-parsley-type but not getting the required results.

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

回答1:


I think that for efficiency and maintainability you should either define a custom validator like explained here or a regex one if you're good at it (((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?(?=.*[#%@!*(()+=]))).{6,16} could do the job?);)




回答2:


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


来源:https://stackoverflow.com/questions/40453419/enforce-strong-password-policy-with-parsley-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!