Created
November 14, 2017 17:00
-
-
Save chriswill0w/8a4003478a83b8ee2a2188412d8ffa21 to your computer and use it in GitHub Desktop.
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
extension String { | |
public var isEmail: Bool { | |
let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) | |
let firstMatch = dataDetector?.firstMatch(in: self, options: .reportCompletion, range: NSRange(location: 0, length: count)) | |
return (firstMatch?.range.location != NSNotFound && firstMatch?.url?.scheme == "mailto") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment