Skip to content

Instantly share code, notes, and snippets.

@mattwymore
Created April 22, 2014 21:10
Show Gist options
  • Save mattwymore/11194402 to your computer and use it in GitHub Desktop.
Save mattwymore/11194402 to your computer and use it in GitHub Desktop.
Email address string validation method
//Got this from http://stackoverflow.com/questions/3139619/check-that-an-email-address-is-valid-on-ios for
//validating whether an email address appears to be valid
- (BOOL) NSStringIsValidEmail:(NSString *)checkString
{
BOOL stricterFilter = YES; // Discussion http://blog.logichigh.com/2010/09/02/validating-an-e-mail-address/
NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}";
NSString *laxString = @".+@([A-Za-z0-9]+\\.)+[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:checkString];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment