Skip to content

Instantly share code, notes, and snippets.

@sdpjswl
Last active August 29, 2015 14:06
Show Gist options
  • Save sdpjswl/ed52132b1cd57be35653 to your computer and use it in GitHub Desktop.
Save sdpjswl/ed52132b1cd57be35653 to your computer and use it in GitHub Desktop.
Email validation regex
+ (BOOL)validateForEmail:(NSString *)email {
NSString *regExPattern = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSRegularExpression *regEx = [[NSRegularExpression alloc] initWithPattern:regExPattern options:NSRegularExpressionCaseInsensitive error:nil];
NSUInteger regExMatches = [regEx numberOfMatchesInString:email options:0 range:NSMakeRange(0, email.length)];
if (regExMatches == 0) {
return NO;
} else {
return YES;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment