InRegex Logo
InRegex
New

Validate Password Strength in JavaScript

Explanation

This regex pattern ensures the password contains at least one digit, one lowercase letter, one uppercase letter, and one special character. It allows passwords to be 8 to 18 characters long.

Javascript

Regular Expression

^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,18}$
Copy
Do you have Feedback?
Javascript

Example Usage

const passwordRegex = /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,18}$/;
const password = 'MyP@ssw0rd';
if (passwordRegex.test(password)) {
    console.log('Valid password');
} else {
    console.log('Invalid password');
}
Copy

Test the expression

Similar Regular Expressions