Skip to content

Instantly share code, notes, and snippets.

@glm4
Created May 7, 2018 18:47
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 glm4/9573d05c99b62f73e202ac14f2fc9cb1 to your computer and use it in GitHub Desktop.
Save glm4/9573d05c99b62f73e202ac14f2fc9cb1 to your computer and use it in GitHub Desktop.
Swift String Extension to validate emails conforming RFC 5322 Internet Message format
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