Created
July 30, 2020 12:59
-
-
Save canberkozcelik/d4d19578f92f382deb664c6fd7e30306 to your computer and use it in GitHub Desktop.
if you ever asked to do some weird password validation (min 6, max 8 digits, no more than 3 repeating or sequential numbers)
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
func isValidPassword() -> Bool { | |
let regex = "\\b(?!.*?(?:0(?:12)|123|234|3(?:45|21)|4(?:56)|5(?:67)|6(?:78)|7(?:89)))(?!.*?(.)\\1{2})[0-9]{6,8}\\b" | |
let sequentialOrRepeated = NSPredicate(format: "SELF MATCHES %@", regex) | |
return sequentialOrRepeated.evaluate(with: self) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change the {6,8} for range and {2} for repeating or sequential parts