I want to validate the email in iOS. I've written a category class and here's my code but in some cases like [email protected] it's not working...
If the user type two times .com or .in continuously it is not detecting it...
I tried with some solutions but that also not working. That's why am asking here
- (BOOL)isValidEmail {
NSString *emailString = [self stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
BOOL isValid = YES;
BOOL sticterFilter = YES;
NSString *stricterFilterString = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSString *laxString = @".+@.+\\.[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = sticterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
if (![emailTest evaluateWithObject:emailString]) {
isValid = NO;
}
return isValid;
}
this regular expression works correctly:
}