Skip to content

Instantly share code, notes, and snippets.

@iceboxi
Created October 26, 2018 09:31
Show Gist options
  • Select an option

  • Save iceboxi/3451770b3d93535a05b01de4ce25d6c1 to your computer and use it in GitHub Desktop.

Select an option

Save iceboxi/3451770b3d93535a05b01de4ce25d6c1 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: NSRegularExpression.MatchingOptions.reportCompletion, range: NSRange(location: 0, length: length()))
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