This regex works if you want to match a password based on the following criteria:
- 8 characters long.
- Must include capital letters.
- Must include small letters.
- Must include numbers.
- Must include special characters.
- NOTE: Can also use
[[:punct:]]
for special characters but it may not be supported by your regex engine.
REGEX:
NOTE: My use of backticks is messing up markdown on this site so I had to add 2 in a row. You only need one backtick! Best just to use the alt solution.
^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[\!-\/\:-\@\[-``\{-\~])(?:.{8})$
ALT REGEX:
^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[[:punct:]])(?:.{8})$
WILL MATCH:
1Ab@1Ab@
%D123!cc
WONT MATCH:
abc
abc123
abC12312
123Abc!!d