Posted By

saturngod on 03/21/11


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

concertman
cnathan
dvel


email validation in iPhone SDK


 / Published in: Objective C
 

  1. NSString *emailRegEx =
  2. @"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
  3. @"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
  4. @"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
  5. @"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
  6. @"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
  7. @"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
  8. @"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
  9.  
  10. NSString* myString=@"[email protected]";
  11.  
  12. NSPredicate *regExPredicate =
  13. [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
  14. BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:myString];

Report this snippet  

You need to login to post a comment.