-1

I have created the following regular expression for validating my email

- (BOOL)isValidEmail
{
    BOOL stricterFilter = YES;
    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:self];
}

But it fails when i enter following:

b. !@#$%^ bfv@mn.cn

Is there any issue with my regular expression?

Umair Suraj
  • 480
  • 11
  • 22

1 Answers1

0

Try this. It's work perfect for me.

 NSString *mailreg=@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *mailtest=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",mailreg];
return [mailtest evaluateWithObject:checkString];
kb920
  • 3,039
  • 2
  • 33
  • 44