Password Validation Regex - Free Pattern & Tester
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$Quick answer
This regex enforces a strong password policy: at least 8 characters, one uppercase letter, one lowercase letter, one number, and one special character.
🛠️ Fix it right here with AI Regex Generator
Need to modify this pattern or generate a new one? Edit the regex below and let our AI help.
Live Regex Tester
Type a string below to see if it matches this pattern.
How it works
It uses lookaheads: (?=.*[a-z]) checks for a lowercase, (?=.*[A-Z]) for uppercase, (?=.*\d) for a number, and (?=.*[@$!%*?&]) for a special character. The [A-Za-z\d@$!%*?&]{8,} ensures the password is at least 8 characters long and only contains allowed characters.
Code Examples
✅ Correct Usage
// JavaScript
const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
console.log(passwordRegex.test("Passw0rd!")); // true❌ What NOT to do
// BAD: Allows "password" or "12345678"
const badRegex = /^.{8,}$/;Frequently asked questions
Why use lookaheads?
Lookaheads allow us to check for the presence of multiple character types anywhere in the string, without consuming characters.
How do I change the minimum length to 12?
Change the {8,} at the end of the regex to {12,}.
Related Search Terms
Related Regex Patterns
Need a custom regex pattern?
Use the free to describe what you need in plain English.
Want an AI with memory for your project?
MonsterX AI remembers your codebase across chats.