php regex for strong password validation

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2010-04-14T13:51:49Z Indexed on 2010/04/14 14:13 UTC
Read the original article Hit count: 400

Filed under:
|
|
|

Hello,

I've seen around the web the following regex

(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$

which validates only if the string:

   * contain at least (1) upper case letter
   * contain at least (1) lower case letter
   * contain at least (1) number or special character
   * contain at least (8) characters in length

I'd like to know how to convert this regex so that it checks the string to

* contain at least (2) upper case letter
* contain at least (2) lower case letter
* contain at least (2) digits
* contain at least (2) special character
* contain at least (8) characters in length

well if it contains at least 2 upper,lower,digits and special chars then I wouldn't need the 8 characters length.

special characters include:

`~!@#$%^&*()_-+=[]\|{};:'".,/<>?

thanks in advance.

© Stack Overflow or respective owner

Related posts about regex

Related posts about php