InRegex Logo
InRegex

Validate Password Strength in JavaScript

Explication

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

Expression Régulière

^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,18}$
Copier
Avez-vous des Retours ?
Javascript

Exemple d'Utilisation

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');
}
Copier

Testez l'expression

Expressions Régulières Similaires