(iPhone) NSPredicate for Text Length & Email Validation

  1. // predicates
  2.         NSPredicate *nameTest;
  3.         NSPredicate *mailTest;
  4.  
  5.         nameTest = [[NSPredicate predicateWithFormat:@"SELF MATCHES %@", @"[a-zA-Z0-9_]{5,}"] retain];
  6.         mailTest = [[NSPredicate predicateWithFormat:@"SELF MATCHES %@", @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}"] retain];
  7.         BOOL isNameOK=[nameTest evaluateWithObject:txtSignUpUserName.text];
  8.         BOOL isEmailOK=[mailTest evaluateWithObject:txtSignUpEmail.text];
This entry was posted in Objective-C and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?

  • Advertisement

  • Categories