Created
August 25, 2021 12:34
-
-
Save thomsmed/39c62d2534233f075005d7c853081b0e to your computer and use it in GitHub Desktop.
Useful String extensions
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
// | |
// 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