Skip to content

Instantly share code, notes, and snippets.

@appyaaron
Created October 26, 2013 22:45
Show Gist options
  • Save appyaaron/7175465 to your computer and use it in GitHub Desktop.
Save appyaaron/7175465 to your computer and use it in GitHub Desktop.
Here is a quick and simple way to validate an email address in iOS.
//Place outside any other methods
- (BOOL)validateEmail:(NSString *)emailStr {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:emailStr];
}
//Place where you wish to validate the email
if(![self validateEmail:[emailAddress text]]) {
//Didn't enter correct email value
} else {
//Did enter correct email value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment