Regex for a Strong Password (Upper, Lower, Digit, 8+ Chars)
Uses lookaheads to require at least one lowercase letter, one uppercase letter, and one digit, with a minimum length.
Published October 11, 2026
This regex uses lookaheads to require at least one lowercase letter, one uppercase letter, one digit and a minimum length of 8.
How the pattern works
Breaking the pattern down: (?=.*[a-z]) = has lowercase; (?=.*[A-Z]) = has uppercase; (?=.*\d) = has digit; .{8,} = at least 8 characters.
Test your regex against both matching and non-matching inputs; use the Regex tool on this site to experiment live.
Pattern tests
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/
✓ 'Passw0rdOK'
✓ 'Abcdef12'
✗ 'password'
✗ 'PASSWORD1'
Practical examples
The pattern
const re = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/Test it
const re = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/
re.test('Passw0rdOK') // true
re.test('Abcdef12') // true
re.test('password') // false
re.test('PASSWORD1') // falseIn Python
import re
re.search(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$', text)Common mistakes
- Over-complex rules that reduce usability.
- Ignoring length (longer is stronger).
- Not checking against breached passwords.
Key takeaways
- Anchors (^ and $) make the whole string match instead of a part of it.
- Regex checks format only; verify data separately when it matters.
- Test with valid and invalid samples.
FAQ
Best password policy?
Prefer length and breach checks over composition rules (NIST guidance).
Where can I test this pattern?
Use the Regex Tester on this site, or regex101.com.