C. Unit
C. Unit

Reputation: 41

Regex for password = one number and both lower and uppercase letters and special characters BUT!! no special characters at start or end

I'm trying to create a Regex for an html5 pattern in a password input.

The password must contain at least:

Any help appreciated

Upvotes: 2

Views: 7677

Answers (1)

wp78de
wp78de

Reputation: 18980

It's not that hard:

(                   # Start of group
    (?=.*\d)        #   must contain at least one digit
    (?=.*[A-Z])     #   must contain at least one uppercase character
    (?=.*[a-z])     #   must contain at least one lowercase character
    (?=.*\W)        #   must contain at least one special symbol
    \w
       .            #   match anything with previous condition checking
        {6,18}      #   length is  characters
    \w 
)                   # End of group

In one line:

((?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*\W)\w.{6,18}\w)

If you do not like \w which is equal to [a-zA-Z0-9_] replace it with that group and remove the underscore.

However, I fully support ctwheels' argument.

Upvotes: 6

Related Questions