Visual regex workbench

Build, test, explain and master regex with visual tools, guides, examples and a growing regex library.

Regex guide

Password Regex Examples

Password validation is one of the most common regex use cases. This guide provides practical password regex examples ranging from simple minimum-length validation to strong password policies.

Minimum 8 characters

Requires at least 8 characters.

Suggested pattern

^.{8,}$
Quick test

What it matches

  • password123
  • mypassword

Common limitations

  • Does not require numbers.
  • Does not require uppercase letters.

Letters and numbers

Requires at least one letter and one digit.

Suggested pattern

^(?=.*[A-Za-z])(?=.*\d).{8,}$
Quick test

What it matches

  • password123
  • abc12345

Common limitations

  • Does not require uppercase letters.
  • Does not require special characters.

Strong password

Requires lowercase, uppercase, number and special character.

Suggested pattern

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

What it matches

  • Password1!
  • MySecure#2026

Common limitations

  • May be considered too restrictive.

Strong password (12+ chars)

A stronger policy requiring at least 12 characters.

Suggested pattern

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

What it matches

  • MySecurePass#2026

Common limitations

  • Long passwords may reduce usability.

Why validate passwords with regex?

Password regex patterns help enforce basic security rules before a password is accepted by an application.

They can require minimum lengths, uppercase letters, lowercase letters, numbers and special characters, helping users create stronger passwords.

Common password requirements

Most modern applications require a minimum password length and encourage a mix of character types.

Typical rules include at least one uppercase letter, one lowercase letter, one digit and one special character.

Strong passwords vs complex passwords

A complex password is not always a strong password. Adding a special character to a short or predictable password does not guarantee good security.

Long passwords and passphrases are often more secure than short passwords with many symbols.

Can regex measure password strength?

Regex can verify whether a password follows formatting rules, but it cannot determine how resistant that password is to attacks.

True password strength depends on length, randomness, uniqueness and resistance to guessing techniques.

Client-side and server-side validation

Regex validation is commonly used on the client side to provide immediate feedback to users.

However, password requirements should always be validated again on the server side because client-side checks can be bypassed.

Common password validation mistakes

Some password policies become so strict that they frustrate users without significantly improving security.

Good validation rules should balance usability, security and maintainability.

Modern password recommendations

Many security organizations now recommend longer passwords and passphrases instead of extremely complex composition rules.

A password manager can help users generate and store secure passwords without having to remember complicated patterns.

Continue learning

๐Ÿ“˜ Recommended guide

Testing Regex

Password regexes should be tested with valid passwords, missing requirements, short values and edge cases.

Do not test only one strong password. Make sure each rule is actually enforced.

Read the complete guide โ†’
๐Ÿ“˜ Recommended guide

Input Validation Best Practices

Password validation should combine regex rules with clear messages, server-side checks and secure storage practices.

Read the complete guide โ†’
๐Ÿ“˜ Recommended guide

Common Regex Mistakes

Password regexes are easy to overcomplicate with too many lookaheads or unclear requirements.

Readable rules are easier to test, explain and maintain.

Read the complete guide โ†’