Skip to content

Instantly share code, notes, and snippets.

@chriswill0w
Created November 14, 2017 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswill0w/8a4003478a83b8ee2a2188412d8ffa21 to your computer and use it in GitHub Desktop.
Save chriswill0w/8a4003478a83b8ee2a2188412d8ffa21 to your computer and use it in GitHub Desktop.
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