Last active
September 20, 2017 15:26
-
-
Save RPallas92/f8069bff9c5c24b14e3cf524f3c0b611 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
func validatePassword(username: String, password:String) -> [String]{ | |
var errors:[String] = [] | |
if password.characters.count < 8 { | |
errors.append("Password must have more than 8 characters.") | |
} | |
if (password.range(of:"[\\W]", options: .regularExpression) == nil){ | |
errors.append("Password must contain a special character.") | |
} | |
if (username == password){ | |
errors.append("Username and password MUST be different.") | |
} | |
return errors | |
} | |
validatePassword(username: "Richi", password: "Richi") | |
/* | |
* Array<String> 3 elements: | |
- 0: "Password must have more than 8 characters." | |
- 1: "Password must contain a special character." | |
- 2: "Username and password MUST be different." | |
*/ | |
validatePassword(username: "Richi", password: "Ricardo$") | |
/* | |
* Array<String> 0 elements | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment