Regular Expressions 101

Community Patterns

Password Complexity Requirement RegEx

1

Regular Expression
PCRE (PHP <7.3)

/
^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\S+$).{8,}$
/

Description

^ # start-of-string (?=.[0-9]) # a digit must occur at least once (?=.[a-z]) # a lower case letter must occur at least once (?=.[A-Z]) # an upper case letter must occur at least once (?=.[@#$%^&+=]) # a special character must occur at least once (?=\S+$) # no whitespace allowed in the entire string .{8,} # anything, at least eight places though $ # end-of-string

Submitted by http://stackoverflow.com/users/18771/tomalak - 8 years ago