JAVASCRIPT
Strong Password Validation with Multiple Regex Rules
Implement robust password validation using a set of regular expressions to enforce length, and character types like uppercase, lowercase, number, and symbol.
function isStrongPassword(password) {
// Minimum 8 characters
if (password.length < 8) return false;
// At least one uppercase letter
if (!/[A-Z]/.test(password)) return false;
// At least one lowercase letter
if (!/[a-z]/.test(password)) return false;
// At least one digit
if (!/[0-9]/.test(password)) return false;
// At least one special character (common set)
if (!/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)) return false;
return true;
}
// Example usage:
console.log(isStrongPassword("Password123!")); // true
console.log(isStrongPassword("weakpass")); // false
console.log(isStrongPassword("Nopassword1")); // false (missing special char)
console.log(isStrongPassword("password!!!")); // false (missing uppercase)
How it works: This JavaScript function validates a password against several common strength criteria using individual regular expressions. It checks for a minimum length of 8 characters, and the presence of at least one uppercase letter, one lowercase letter, one digit, and one special character. This modular approach provides clear, separable rules for password complexity.