Regex for Strong Password

All patterns
Validation55 chars

Regex for Strong Password

This pattern enforces a minimum length plus lower, upper, digit, and symbol presence. It is useful for UI hints, but real password policy should still be enforced server-side.

The expression

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z\d]).{12,}$/

How to read it

Anchor: the match must start at the beginning of the string.

Anchor: the match must run to the end of the string.

\d matches a single digit, 0 through 9.

A brace quantifier fixes how many times the previous token repeats.

A negated class [^ … ] matches anything except the listed characters.

Validate your own text, line by line

no input
Try:

This expression is anchored, so it asks whether a whole string is valid. Each line above is tested on its own — it will not find a match inside a longer sentence.

Examples, checked in your browser

4/4 verified

Tr0ub4dor&3!

Matches.

A-Longer9#Pass

Matches.

short1A!

No match — this is the kind of input the pattern rejects.

alllowercase123!

No match — this is the kind of input the pattern rejects.

Use it in code

3 languages
JavaScript
const regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z\d]).{12,}$/g;
regex.test(input);
Python
import re
pattern = re.compile(r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z\d]).{12,}$")
bool(pattern.search(input))
Go
re := regexp.MustCompile("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[^A-Za-z\\d]).{12,}$")
matched := re.MatchString(input)

Other validation patterns

6
GroupValidation
Flagsnone
Examples4
SafetyOK