Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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