Skip to content

Instantly share code, notes, and snippets.

@thomsmed
Created August 25, 2021 12:34
Show Gist options
  • Save thomsmed/39c62d2534233f075005d7c853081b0e to your computer and use it in GitHub Desktop.
Save thomsmed/39c62d2534233f075005d7c853081b0e to your computer and use it in GitHub Desktop.
Useful String extensions
//
// String+Extensions.swift
//
import Foundation
extension String {
var isEmail: Bool {
// https://www.tutorialspoint.com/email-and-phone-validation-in-swift
let regularExpressionForEmail = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let testEmail = NSPredicate(format: "SELF MATCHES %@", regularExpressionForEmail)
return testEmail.evaluate(with: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment