In iOS App, how to add Email validation on UITextField?
A version using NSRegularExpression and regex pattern copied from OWASP_Validation_Regex_Repository
+ (BOOL) isValidEmail:(NSString *)emailString {
NSError *error = NULL;
/**
* @see OWASP_Validation_Regex_Repository
*/
NSString *emailPattern = @"^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:emailPattern
options:NSRegularExpressionCaseInsensitive
error:&error];
NSUInteger matchCount = [regex numberOfMatchesInString:emailString options:0 range:NSMakeRange(0, [emailString length])];
return matchCount > 0;
}