Created
May 7, 2018 18:47
-
-
Save glm4/9573d05c99b62f73e202ac14f2fc9cb1 to your computer and use it in GitHub Desktop.
Swift String Extension to validate emails conforming RFC 5322 Internet Message format
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
extension String { | |
//Regex fulfill RFC 5322 Internet Message format | |
func isEmailFormatted() -> Bool { | |
let predicate = NSPredicate(format: "SELF MATCHES %@", "[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?\\.)+[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?") | |
return predicate.evaluate(with: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment