priore

Validate a email from a string

Apr 23rd, 2015
945
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×