Password checker keeps approving passwords with no digits, help.
function validatePassword(pw) {
const rules = [
{ test: /.{8,}/, msg: "At least 8 characters" },
{ test: /[A-Z]/, msg: "One uppercase letter" },
{ test: /[a-z]/, msg: "One lowercase letter" },
{ test: /[0-9]/g, msg: "One digit" },
{ test: /[!@#$%^&*]/, msg: "One special character" }
];
const failed = rules.filter(rule => !rule.test.test(pw));
return failed.length === 0
? "Password is strong!"
: "Missing: " + failed.map(r => r.msg).join(", ");
}
console.log(validatePassword("Abcdefgh1!"));
console.log(validatePassword("Abcdefgh1!"));
Reply with what is broken and how you would fix it.