Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created February 23, 2020 20:54
Show Gist options
  • Save foxicode/94cb7ef824d486ec7b6acef818f9fbbf to your computer and use it in GitHub Desktop.
Save foxicode/94cb7ef824d486ec7b6acef818f9fbbf to your computer and use it in GitHub Desktop.
Swift String extension checking if String contains valid email address
import Foundation
extension String {
var isValidEmail: Bool {
let 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: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment