Regex for Password Must Contain At Least Eight Characters, At Least One Number and Both Lower and Uppercase Letters and Special Characters

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

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.

Password pattern wont accept this special characters like <>,./'";

(?=.*[0-9])         require one digit anywhere
(?=.*[a-z]) require one lowercase letter anywhere
(?=.*[A-Z]) require one uppercase letter anywhere
(?=.*[^0-9a-zA-Z]) require one symbol anywhere
^.{8,26}$ match any string of 8 to 26 characters

Combine all of these together and you get:

^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[^0-9a-zA-Z]).{8,26}$

This, of course, counts anything that isn't a letter from A to Z or a digit as a special character, including accented letters, letters from other alphabets, and whitespace.



Related Topics



Leave a reply



Submit