SHARE
TWEET

Validate a email from a string

priore Apr 23rd, 2015 729 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (BOOL)isValidEmailWithString:(NSString*)string
  2. {
  3.     if ([string length] > 0) {
  4.         BOOL stricterFilter = NO;
  5.         NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}";
  6.         NSString *laxString = @".+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2}[A-Za-z]*";
  7.         NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
  8.         NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
  9.         return [emailTest evaluateWithObject:string];
  10.     }
  11.    
  12.     return NO;
  13. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top