Created
March 11, 2019 12:45
-
-
Save amadeu01/d4370ea0b95a290d4e3d70b95094826c to your computer and use it in GitHub Desktop.
String nice extensions
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
| private let firstpart = "[A-Z0-9a-z]([A-Z0-9a-z._%+-]{0,30}[A-Z0-9a-z])?" | |
| private let serverpart = "([A-Z0-9a-z]([A-Z0-9a-z-]{0,30}[A-Z0-9a-z])?\\.){1,5}" | |
| private let emailRegex = firstpart + "@" + serverpart + "[A-Za-z]{2,8}" | |
| private let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegex) | |
| extension String { | |
| var isEmail: Bool { | |
| return emailPredicate.evaluate(with: self) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment