Created
March 6, 2018 15:06
-
-
Save dodikk/5dcc842344a1e9d7bb484d2bcc7333d0 to your computer and use it in GitHub Desktop.
Email validation regex from bootstrap
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
private static func validateEmailByBootstrapRegex(_ userInput: String) -> Bool | |
{ | |
var emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | |
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegex) | |
return emailTest.evaluate(with: userInput) | |
} | |
// TODO: is NSPredicate any better | |
// than `(NSPredicate.numberOfMatches == 1)` ? | |
// | |
// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NSPredicate is less code