Regular Expressions 101

Community Patterns

Community Library Entry

3

Regular Expression
PCRE (PHP <7.3)

/
^ # start of line (?=(?:.*[A-Z]){2,}) # 2 upper case letters (?=(?:.*[a-z]){2,}) # 2 lower case letters (?=(?:.*\d){2,}) # 2 digits (?=(?:.*[!@#$%^&*()\-_=+{};:,<.>]){2,}) # 2 special characters (?!.*(.)\1{2}) # negative lookahead, dont allow more than 2 repeating characters ([A-Za-z0-9!@#$%^&*()\-_=+{};:,<.>]{12,20}) # length 12-20, only above char classes (disallow spaces) $ # end of line
/
gmx

Description

This regex matches only when all the following are true:

  1. password has minimum 2 uppercase letters
  2. password has minimum 2 lowercase letters
  3. password has minimum 2 numerals (0-9)
  4. password has minimum 2 special characters, of the group !@#$%^&*()-_=+{};:,<.>
  5. password has no more than 2 consecutive identical characters
  6. password is composed of 12 to 20 characters belonging ONLY to the above character classes (i.e., no whitespace)
Submitted by anonymous - 7 years ago