★ Identity & contact · regex
Regex for Strong Password
Four lookaheads each require one character class somewhere in the string, then .{12,} enforces the length. It's a common policy, though length matters far more than character classes.
- Runs in your browser
- No signup
Try the strong password pattern
Read it in plain English (best-effort)
- ^start of a line
- (?=lookahead: what follows must match…
- .any character except a newline
- *zero or more of the previous
- [a-z]one character from: a–z
- )end of group
- (?=lookahead: what follows must match…
- .any character except a newline
- *zero or more of the previous
- [A-Z]one character from: A–Z
- )end of group
- (?=lookahead: what follows must match…
- .any character except a newline
- *zero or more of the previous
- \da digit (0–9)
- )end of group
- (?=lookahead: what follows must match…
- .any character except a newline
- *zero or more of the previous
- [^A-Za-z0-9]any one character except A–Z, a–z, 0–9
- )end of group
- .any character except a newline
- {12,}12 or more of the previous
- $end of a line
One sample per line works well with the m flag on anchored patterns.
The pattern, piece by piece
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}$/| Part | What it does |
|---|---|
(?=.*[a-z]) | lookahead: at least one lowercase letter somewhere |
(?=.*[A-Z]) | lookahead: at least one uppercase letter |
(?=.*\d) | lookahead: at least one digit |
(?=.*[^A-Za-z0-9]) | lookahead: at least one symbol |
.{12,} | then 12 or more characters of anything |
What it accepts and rejects
Every sample below is checked automatically in JavaScript and Python. The tester above is preloaded with all of them, one per line.
| Should match | |
|---|---|
Tr0ub4dor&3xx | ✓ |
C0rrect-Horse! | ✓ |
Aa1!Aa1!Aa1! | ✓ |
My$ecretPass9 | ✓ |
Founder#2026ok | ✓ |
zZ9@zZ9@zZ9@ | ✓ |
| Should not match | |
|---|---|
short1!A | ✗ |
alllowercase1! | ✗ |
ALLUPPERCASE1! | ✗ |
NoDigitsHere!! | ✗ |
NoSymbols12345 | ✗ |
Aa1!Aa1!Aa1 | ✗ |
Copy it into your code
Go noteGo's RE2 engine has no lookaheads, so check each rule separately. The Go tab shows a version without regex.
const strongPasswordRe = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}$/;
export function isValidStrongPassword(value) {
return strongPasswordRe.test(value.trim());
}When not to use regex for this
Current NIST guidance favours long passphrases and checking against breached-password lists over composition rules. Use a strength estimator like zxcvbn and the Have I Been Pwned range API; keep this regex only if a policy requires it.
Questions engineers actually ask
Are composition rules still recommended?
Why do lookaheads work here?
What is catastrophic backtracking?
Sources
Formats were checked on 8 November 2026. Rules change; the official issuer wins if it disagrees.
More identity & contact patterns
- US Phone NumberNANP numbers in common formats, capturing area code, exchange and line.^(?:\+?1[ .-]?)?\(?([2-9][0-9]{2})\)?[ .-]?([2-9][0-9]{2})[ .-]?([0-9]{4})$
- E.164 Phone NumberInternational numbers in E.164: +, country code, up to 15 digits.^\+[1-9][0-9]{6,14}$
- US ZIP CodeFive-digit ZIP codes with an optional ZIP+4 suffix.^[0-9]{5}(?:-[0-9]{4})?$
- Username3–16 characters, starts with a letter, letters, digits and underscores only.^[a-zA-Z][a-zA-Z0-9_]{2,15}$
- Credit Card Number Format16-digit cards in groups of four, and 15-digit Amex in 4-6-5. Format only.^(?:(?:\d{4}[ -]?){3}\d{4}|3[47]\d{2}[ -]?\d{6}[ -]?\d{5})$
Or browse the full regex library.
More from the workbench
Fine print
Tools: on the house.
Engineer: by the hour.
The regex was free. Code that doesn't need one is the upgrade: typed schemas, validated once at the edge, trusted everywhere after.
I'm Himanshu, an AI and full-stack engineer. I build MVPs, AI agents and the growth plumbing around them for early-stage startups.
