Free · runs in your browser

Password Regex Tester

Password Regex Tester. Paste a regex pattern to instantly test it live against a list of sample passwords. It only takes a moment to build a password validation regex, and nothing you enter ever leaves your device.

Your values

JavaScript flavour. Enter the pattern alone or as /pattern/flags; flags written after the closing slash are added to the ones ticked below. Up to 2,000 characters; a test that runs longer than 2 seconds is stopped.

Flags

In one-password-per-line mode each line is tested on its own, so g only matters in whole-text mode.

Test mode

Runs in your browser only; nothing is sent or stored. Spaces count as characters, so they are not trimmed. Up to 2,000 passwords or 100,000 characters.

Result

Result
—
Match
—
Rejected (and the check each one fails)
—
Capture groups (first match)
—
Pattern
—
  • No account, no logging
  • Open formulas explained below
  • Works offline once loaded

Paste a candidate string into this password regex tester and you see in one glance whether your regular expression accepts it, which rule rejected it, and why. Instead of shipping a guess and hoping, you can validate password rules against real user input and keep the minimum length, case sensitivity and special characters under control before they reach production.

How a Password Regex Tester Works

A password regex is a single pattern that describes what an acceptable password looks like. A tester runs it against whatever you type, usually on every keystroke, and reports pass or fail. Because the same engine your application uses does the matching, there are no surprises later: if the tester says a string matches, your JavaScript will agree.

The idea behind a regex pattern for passwords is that one search pattern can express every rule at once. Without it, developers write a chain of if statements, one per rule, which is error-prone and hard to maintain when the product team changes the requirements. With it, the whole policy lives in a single line of code you can read, test and swap.

Why Password Validation Uses Anchors and Lookaheads

Every serious pattern starts with ^ and ends with $. These anchors force the match to cover the entire string, not just a fragment inside it. Between them sit the rules, and each rule is a zero-width check written as (?=...) that peeks ahead without consuming characters. Because nothing is consumed, you can stack as many of these checks as you like and every one of them gets a vote on the same input.

Reading One Rule Piece by Piece

A positive lookahead such as (?=.*\d) reads as: from the start, skip any run of characters, then require a digit. If a digit exists anywhere, the check succeeds and the engine moves on to the next one. That is how at least one digit, at least one capital and at least one symbol can be demanded in any order.

The Strong Password Regex Used in This Walkthrough

Here is the strong password regex we use for every test below. It requires a lowercase letter, an uppercase letter, one digit, a symbol, and a length of 12 or more: Run your input through the free pci dss password compliance checker to get a detailed breakdown in seconds.

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

In plain terms, a password is accepted only when all five conditions hold together:

$$\text{valid} = \text{lower} \land \text{upper} \land \text{digit} \land \text{symbol} \land (n \ge 12)$$
  • (?=.*[a-z]) demands at least one lowercase character.
  • (?=.*[A-Z]) demands at least one capital character.
  • (?=.*\d) demands one number, meaning a digit from 0 to 9.
  • (?=.*[^\w\s]) demands at least one special character, meaning anything that is neither a letter, digit, underscore nor space.
  • .{12,} sets the length floor so the whole thing is at least 8 characters long, with room to spare.

Testing Sample Passwords Step by Step

Now test it against six strings and read each verdict. We ran each of them through the expression above and recorded the result:

Testing Sample Passwords Step by Step
InputLengthRules metVerdict
maplefoxrun11lowercase onlyRejected
MapleFoxRun202415lower, upper, digit; no symbolRejected
Maple#Fox910all four classes; below 12Rejected
Maple#Fox2024Run16all four classes and lengthAccepted
maple fox#Run9 216all four classes and lengthAccepted
Kettle!Orbit58Dune18all four classes and lengthAccepted

The first input is too short and has no variety, a clear very weak case. The second looks respectable, yet it fails because it has no symbol. The third has everything except length. Only the last three satisfy every rule at once. Notice that maple fox#Run9 2 is accepted even though it contains spaces, because the final .{12,} accepts any character. If your validation rules forbid spaces, replace the dot with an explicit character class.

Grid showing which of five rules each of six sample passwords passes under the strong password regex
Rule-by-rule results for the six test inputs.

Running the Same Check in JavaScript

The browser's built-in RegExp object exposes test(), which takes text and gives back a boolean. A short function is all you need:

const rule = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{12,}$/;
function isAccepted(candidate) { return rule.test(candidate); }
isAccepted("maplefoxrun");        // false
isAccepted("Maple#Fox2024Run");   // true

That is the whole password regex javascript validator: one constant, one function. The sample output matches the table. The first call returns false because three of the four classes are missing, and the second returns true because nothing is missing.

Adjusting the Regular Expression for Different Password Rules

Different products need different strictness, and the expression bends easily. Every tweak is a one-token change:

  1. Change the length. Edit {12,} to {8,} for an eight characters floor, or to {12,64} to cap it as well.
  2. Drop a rule. Delete one check and that requirement disappears.
  3. Restrict the symbol set. Swap [^\w\s] for [!@#$%^&*] if your backend only accepts certain marks.
  4. Allow spaces or letters outside A to Z. Use a Unicode-aware class so accented letters count.
Dumbbell chart comparing the length of six sample passwords with the 12-character minimum length rule
How far each sample input sits from the 12-character minimum.

Building a Medium Strength Variant

A medium strength tier is useful when you want to nudge people without blocking them. A common version needs six characters and any two of three groups: lowercase, uppercase or digit. You express the alternatives with the | operator:

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

Run your commonly used passwords through it and watch how many land in the middle tier. That tells you whether the tier is too generous.

Escaping Inside a Character Class

Most special characters lose their meaning inside square brackets, but a few still bite. A hyphen must come first or last, and a caret must not come first. In a RegExp built from text you also have to double each backslash, which is why escaping mistakes are the number one reason an expression behaves differently in a string than in a literal.

Edge Cases to Test Before You Ship

An expression that survives the happy path can still break on the odd inputs real people type. Before you trust the rule, run each of these through the tester:

  • A secret of exactly 12 characters, such as Kettle!Orbi9, to confirm the boundary is inclusive.
  • An empty field, which must fail every check.
  • A very long paste of a thousand characters, to make sure matching stays fast.
  • An emoji or accented letter, because JavaScript counts each emoji as two UTF-16 units.
  • Leading or trailing spaces left behind by a password manager.

Passwords are typed on phones, pasted from vaults and autofilled by browsers, so the more odd inputs you try, the fewer surprises your sign-up flow produces.

Password Strength Scoring and User Feedback

A yes-or-no answer is blunt. For web forms, password strength labels are friendlier, and feedback that names the missing rule teaches users what to fix. The usual approach is to score character variety: add one point for each class present, then map the score to a label.

Password Strength Scoring and User Feedback
Classes presentLabelSuggested message
1Very weakAdd capitals, digits and symbols
2WeakAdd a digit or symbol
3MediumOne more class to go
4StrongLooks good

Show a colored bar beside the field and update it as the user types. That live feedback in a signup form or on login forms cuts abandoned registrations far more than an error message after submit.

How to Test Password Strength in JavaScript Code

To test password strength in your own JavaScript code, count the character classes with four tiny checks and map the total to a label from the table above:

const checks = [/[a-z]/, /[A-Z]/, /\d/, /[^\w\s]/];
const score = (text) => checks.filter((c) => c.test(text)).length;

Feed it Maple#Fox2024Run and the score is 4. Feed it maplefoxrun and the score is 1. Any weak password lands on 1 or 2, so the label tells people which step to take next. The helper never replaces the full regex, because it only explains the verdict. Since it is plain JavaScript, it drops into a React or Vue component, and the code stays short enough to read in one glance. Good password strength meters reward length first, then variety.

Why Entropy Matters More Than Rules

Entropy measures how hard a secret is to guess. For a random secret drawn from a pool of R symbols with length L, it is roughly:

$$H = L \times \log_{2}(R)$$

With all 94 printable ASCII characters in the pool and 16 characters, the upper bound is 16 × 6.55, or about 104.9 bits. A human-chosen secret such as Maple#Fox2024Run is far more predictable than that, because words and years follow patterns, so treat the figure as a ceiling rather than a promise. No regex can measure real unpredictability: the rule from the walkthrough accepts Maple#Fox2024Run even though its real strength sits far below that ceiling, which is why the checker is a gate for format and never a score for secrecy.

Debugging a Rejected Passphrase with a Password Checker

A support ticket arrives: a customer says the account page refuses Harbor-Lantern-47-Quill, a 23-character passphrase from their vault. The current rule in the codebase is ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d@#$%]{10,20}$. You paste both into the tester, which works as a password checker for exactly this kind of complaint: each verdict points at the clause of the expression that needs editing, so the ticket becomes a regex fix instead of a guess.

The verdict is a fail, and two things explain it. The final class lists only letters, digits and four symbols, so the hyphens are illegal, and {10,20} caps the length at 20 while the passphrase runs 23. Trimming it to HarborLantern47Quill gives exactly 20 characters and passes, which confirms both diagnoses.

Debugging a Rejected Passphrase with a Password Checker
InputLengthOld ruleNew rule
Harbor-Lantern-47-Quill23Fail (hyphen, over 20)Pass
HarborLantern47Quill20PassPass
Harbor Lantern 47 Quill23Fail (spaces)Fail (spaces)

The replacement is ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)\S{12,64}$. It keeps the three class checks, raises the floor to 12 to match NIST SP 800-63B's published guidance that long secrets beat composition tricks, lifts the cap to 64 for the password rule on the account page, and swaps the restricted class for \S, so any visible character is allowed. All three rows in the table reflect that run, and the spaced version still fails because \S rejects whitespace. That is a deliberate choice, noted in the ticket, and the next step is a re-run of the passphrase list from the support queue before the change ships.

Where Password Validation Falls Short

A pattern checks shape, not safety. A choice like Password1! passes most rules and is still one of the first guesses in any brute force run. Because brute-force attacks test commonly used passwords first, shape checks alone cannot stop them. For real security, add these layers:

  • Compare each new password against a list of leaked passwords and common entries.
  • Run the real check on the server too; client-side validation is a convenience, never the only gate.
  • Store only a salted hash in your storage layer, never the raw text, and never encode a secret with a reversible scheme.
  • Treat credentials, session tokens and reset links as separate problems from format rules.
A rule that only checks what a password looks like cannot tell you whether anyone has guessed it before.

Real-World Examples of Rule Failures

Among the real-world examples teams hit most often: an expression copied from a tutorial that forbids the very symbols a password manager generates, a minimum that silently rejects non-ASCII letters for users who type in other languages, and a length cap that is lower than the manager's default. Each one turns into a support ticket. Testing with real Unicode input is the cheap way to catch them.

Using a Password Validator in Your Own Project

The same expression works in any engine, with small differences. In a JavaScript front end you call test() on submit or on input. In a Node.js API, run the same literal inside the request handler before hashing. For authentication flows, apply it only when a password is created or changed, never at login, since the stored value is a hash and the original format rules no longer apply.

Keep a short documentation note beside the constant that lists what each rule enforces. That small habit makes the next edit safe, because the next developers to open the file can see the intent without decoding the symbols. It also doubles as a quick tutorial for new teammates.

These password rules and requirements are the starting point, and the criteria you finally pick should come from your own threat model. Test every change here first, keep the tests as a checklist, and revisit them whenever the policy moves. The pattern matching engine will do exactly what you tell it, so tell it precisely.

Frequently Asked Questions

Why does my regex say it's invalid?
JavaScript's regex engine will reject patterns with unbalanced parentheses/brackets, invalid quantifiers, or unsupported syntax from other regex flavors (like PCRE-specific features). The error message shown comes directly from the browser's own regex parser and usually points at what's wrong.
What do the i, m, and u flags do?
'i' makes the match case-insensitive (A matches a). 'm' changes how ^ and $ behave with multi-line input (rarely needed for single-line passwords). 'u' enables full Unicode mode, which matters if your pattern or samples include characters outside the basic ASCII range (like emoji or accented letters) and you're using Unicode property escapes.
Can I test a regex meant for Python or PHP here?
Mostly -- core regex syntax (character classes, quantifiers, lookaheads) is shared across languages, so a pattern will usually behave identically. Watch for flavor-specific features: Python's regex module supports some syntax JavaScript doesn't, and PCRE (PHP) has its own extensions -- if a pattern fails to parse here but works in your language, that's likely why.
Does pasting my real passwords here send them anywhere?
No -- matching happens entirely in your browser using JavaScript's built-in RegExp engine. Nothing you type is transmitted, logged, or stored. That said, prefer representative dummy values over real credentials when testing, as a general habit.
How do I build a regex from scratch instead of testing an existing one?
Use the Password Validation Regex Builder instead -- set your length and character-class requirements there and it generates the pattern for you, which you can then paste in here to test against real sample values.

About the author

Vinitha Pu

Founder and designer

Vinitha Pu is a graphic designer based in Palakkad, Kerala, who builds free, privacy-friendly browser tools. She studied Textile and Apparel Design at Avinashilingam University and completed a C-Tech in Graphic Design at Image Creative Education in 2025. She designs, builds and maintains the password generators, strength checkers, hash tools and security calculators on PasswordHive.

  • Content author: Vinitha Pu
  • Fact checked by: Vinitha Pu. Each tool's output is checked against official test vectors or a reference implementation, and every strength and crack-time figure against the formula it uses, before it goes live.
  • Published Updated