Created
March 15, 2020 16:00
-
-
Save foxicode/2d8e8f00be79aac861c64a619aaa7372 to your computer and use it in GitHub Desktop.
Alternative way to check if String is email (Swift)
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 { | |
| func matches(_ expression: String) -> Bool { | |
| if let range = range(of: expression, options: .regularExpression, range: nil, locale: nil) { | |
| return range.lowerBound == startIndex && range.upperBound == endIndex | |
| } else { | |
| return false | |
| } | |
| } | |
| var isValidEmail: Bool { | |
| matches("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment