Skip to content

Instantly share code, notes, and snippets.

@qdequele
Created June 10, 2015 06:50
Show Gist options
  • Save qdequele/51aac6419a957eef0bf2 to your computer and use it in GitHub Desktop.
Save qdequele/51aac6419a957eef0bf2 to your computer and use it in GitHub Desktop.
How to know if string is a email with a swift regex
func isValidEmail(testStr:String) -> Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
return emailTest.evaluateWithObject(testStr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment