I\'m trying to check if some email address is correct with the following code :
NSPredicate *regexMail = [NSPredicate predicateWithFormat:@\"SELF MATCHES \'.*@.*
This is the regular expression used by the iOS Mail application to validate an email address:
^[[:alnum:]!#$%&’*+/=?^_`{|}~-]+((\.?)[[:alnum:]!#$%&’*+/=?^_`{|}~-]+)*@[[:alnum:]-]+(\.[[:alnum:]-]+)*(\.[[:alpha:]]+)+$
And here is a copy/paste ready function using this regular expression to validate an email address in Objective-C:
BOOL IsValidEmail(NSString *email)
{
// Regexp from -[NSString(NSEmailAddressString) mf_isLegalEmailAddress] in /System/Library/PrivateFrameworks/MIME.framework
NSString *emailRegex = @"^[[:alnum:]!#$%&'*+/=?^_`{|}~-]+((\\.?)[[:alnum:]!#$%&'*+/=?^_`{|}~-]+)*@[[:alnum:]-]+(\\.[[:alnum:]-]+)*(\\.[[:alpha:]]+)+$";
NSPredicate *emailPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailPredicate evaluateWithObject:email];
}