简体   繁体   中英

Enforce strong password policy with parsley.js

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> 

我认为,为了提高效率和可维护性,您应该定义一个自定义验证器(如此处所述) 或者如果您擅长于它,则应定义一个正则表达式( ((?=.*\\d)(?=.*[az])(?=.*[AZ])(?(?=.*[#%@!*(()+=]))).{6,16}可以完成这项工作?);)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM