Last active
December 4, 2017 09:23
-
-
Save alexanderkhitev/93bee949907d4c482bb8d413800daeda to your computer and use it in GitHub Desktop.
isValidEmail string extension for swift 3
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
var isValidEmail: Bool { | |
do { | |
let regex = try NSRegularExpression(pattern: "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}", options: .caseInsensitive) | |
return (regex.firstMatch(in: self, options: [], range: NSMakeRange(0, self.characters.count)) != nil) | |
} catch { | |
debugPrint(error.localizedDescription) | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment