Last active
July 19, 2017 13:11
-
-
Save dbrack/d6ee62132cf109ebfedc03cb16510779 to your computer and use it in GitHub Desktop.
Simple password validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const validatePassword = (pw: string) => { | |
const minimumLength = 5; | |
const amountOfCriteria = 1; | |
const isLongEnough = (pw: string) => pw.length >= minimumLength; | |
const containsDigit = (pw: string) => ( | |
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
.some(n => pw.includes(String(n))) | |
); | |
return Array.of(isLongEnough, containsDigit) | |
.map(f => f(pw)) | |
.filter(fulfilled => fulfilled) | |
.length > amountOfCriteria; | |
} | |
alert(`password fulfills requirements: ${validatePassword('veryC0mplex')}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment