Advertisements
Validate Email
The following code helps to validate email string(NSString).
+ (BOOL)isValidEmail:(NSString *)email stricterFilter:(BOOL)stricterFilter{ 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:email]; }