Skip to content

Instantly share code, notes, and snippets.

@meteochu
Created May 22, 2017 18:57
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 meteochu/fb3718462b26973df9e63ed6fdf3f2f4 to your computer and use it in GitHub Desktop.
Save meteochu/fb3718462b26973df9e63ed6fdf3f2f4 to your computer and use it in GitHub Desktop.
import Foundation
extension String {
var isValidEmail: Bool {
let emailRegEx = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
return NSPredicate(format:"SELF MATCHES %@", emailRegEx).evaluate(with: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment