Invalid email address MFMailComposeViewController?

I am using MFMailComposeViewController so that the user can send emails in the application. Same:

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

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

I noticed that if he is assigned an invalid email address, he simply does not put it in the recipients field, is there anyway that this is happening? Or override this?

Thank.

+3
source share
1 answer

First, verify 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 an argument to the NSStringIsValidEmail: method. It will return YES if it is valid, NO otherwise.

+1
source

All Articles