Validate a password by reporting which rules failed.
Build a small password validator. Each rule should live in its own function, and the final validator should report which rules failed.
Write these functions:
hasMinimumLength(password) should return true when the password has at least 8 characters.
hasNumber(password) should return true when the password contains at least one number.
hasUppercaseLetter(password) should return true when the password contains at least one uppercase letter.
getFailedRules(password) should return an array of missing rule names.
validatePassword(password) should return an object with valid and failedRules.
Sample checks:
Expected output:
Use "minimum length", "number", and "uppercase letter" as the failed rule names.
Join the Community
roadmap.sh is the most starred project on GitHub and is visited by hundreds of thousands of developers every month.
Roadmaps Best Practices Guides Videos FAQs YouTube
roadmap.sh by @kamrify @kamrify
Community created roadmaps, best practices, projects, articles, resources and journeys to help you choose your path and grow in your career.
Login or Signup
You must be logged in to perform this action.