Skip to content

Instantly share code, notes, and snippets.

@canberkozcelik
Created July 30, 2020 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canberkozcelik/d4d19578f92f382deb664c6fd7e30306 to your computer and use it in GitHub Desktop.
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)
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)
}
@canberkozcelik
Copy link
Author

change the {6,8} for range and {2} for repeating or sequential parts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment