PDA

View Full Version : Validate an Email Address




MarcVanH
Sep 25, 2008, 12:15 PM
I thought I had found a great bit of code for validating an email address using regular expressions,

- (BOOL)isValidEmail:(NSString*)myEmail
{
NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
//Valid email address
return ([emailTest evaluateWithObject:myEmail]) ;
}


But then I found out NSPredicate does not work on the phone (only the simulator).

Has anyone by chance written working code to validate an email address on the iPhone?