Skip to content

Instantly share code, notes, and snippets.

@aronhoyer
Created May 31, 2020 23:16
Show Gist options
  • Save aronhoyer/b626d252784612777aa90a5b09d3b442 to your computer and use it in GitHub Desktop.
Save aronhoyer/b626d252784612777aa90a5b09d3b442 to your computer and use it in GitHub Desktop.
function passwordIsValid(password) {
if (password.length < 8 || password.length > 255) return false
const upper = []
const lower = []
const num = []
const special = []
password.split("").forEach(c => {
if (upper.length === 0 && c.match(/[A-Z]/)) upper.push(c)
if (lower.length === 0 && c.match(/[a-z]/)) lower.push(c)
if (num.length === 0 && c.match(/[0-9]/)) num.push(c)
if (special.length === 0 && c.match(/[@_-"!?+`´#$%&/()^¨*><,.;:]/)) special.push(c)
})
return !!upper.length && !!lower.length && !!num.length && !!special.length
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment