Created
August 10, 2017 03:28
-
-
Save farishkash/aa56198a5db0905da93e4b708ebd26eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function isLetter(str) { | |
return str.length === 1 && str.match(/[a-z]/i); | |
} | |
function hasUppercase(input) { | |
for (var i = 0; i < input.length; i++) { | |
if (isLetter(input[i]) == input[i].toUpperCase()) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function hasLowercase(input) { | |
for (var i = 0; i < input.length; i++) { | |
if (isLetter(input[i]) == input[i].toLowerCase()) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function isLongEnough(input) { | |
if (input.length >= 8) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function hasSpecialCharacter(input) { | |
var specialCharacters = ['!', '@', '#', '$', '%', '^', '&', '*']; | |
for (var i = 0; i < input.length; i++) { | |
for (var j = 0; j < specialCharacters.length; j++) { | |
if (input[i] == specialCharacters[j]) { | |
return true; | |
} | |
} | |
} | |
} | |
function isPasswordValid(input) { | |
if (hasUppercase(input) === true && hasLowercase(input) === true && isLongEnough(input) === true && hasSpecialCharacter(input) === true) { | |
console.log('The password is valid.'); | |
} else if (!hasUppercase(input)) { | |
console.log('The password needs a capital letter.'); | |
} else if (!hasLowercase(input)) { | |
console.log('The password needs a lower case letter.'); | |
} | |
if (!isLongEnough(input)) { | |
console.log('The password needs at least 8 letters.'); | |
} | |
if (!hasSpecialCharacter(input)) { | |
console.log('The password should have a special character'); | |
} | |
} | |
isPasswordValid('pPpppppppppp@'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment