Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MFMailComposeViewController Invalid Email Address?

I am using MFMailComposeViewController so the user can email in app. Just like so:

MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];

[mail setToRecipients:[NSArray arrayWithObject:emailString]];
mail.mailComposeDelegate = self;
[self presentModalViewController:mail animated:YES];

I have noticed if an invalid email address is given to it it simply doesn't put it into the recipients field, is there anyway of me taking action of this happens? Or overriding this?

Thanks.

like image 905
Josh Kahane Avatar asked Nov 23 '25 14:11

Josh Kahane


1 Answers

First try to validate your email Address. Use this code below

    -(BOOL) NSStringIsValidEmail:(NSString *)checkString
    {
          NSString *stricterFilterString = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
          NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", stricterFilterString];
          return [emailTest evaluateWithObject:checkString];
    }

Pass your email string as argument to NSStringIsValidEmail: method. It will return YES if valid, NO otherwise.

like image 197
rakeshNS Avatar answered Nov 25 '25 03:11

rakeshNS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!