Created
February 23, 2020 20:54
-
-
Save foxicode/94cb7ef824d486ec7b6acef818f9fbbf to your computer and use it in GitHub Desktop.
Swift String extension checking if String contains valid email address
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
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