Enforce strong password requirements with regex: minimum 8 characters, uppercase, lowercase, digit, and special character.
/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}/| Token | Meaning |
|---|---|
(?=.*[a-z]) | Lookahead: must contain at least one lowercase letter |
(?=.*[A-Z]) | Lookahead: must contain at least one uppercase letter |
(?=.*\d) | Lookahead: must contain at least one digit |
(?=.*[!@#$%^&*]) | Lookahead: must contain at least one special character (!@#$%^&*) |
.{8,} | Match 8 or more of any characters |
P@ssw0rd!MatchStr0ng#PassMatchAb1!xxxxMatchweakNo matchnouppercase1!No matchNOLOWER1!No matchNoDigit!!No matchconst passwordRegex = /(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}/;
const password = "P@ssw0rd!";
const isStrong = passwordRegex.test(password);
console.log(isStrong); // trueimport re
password_regex = r'(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}'
password = "P@ssw0rd!"
is_strong = bool(re.match(password_regex, password))
print(is_strong) # TrueWant to test this pattern with your own data?
Try this pattern in Regex Tester →