ios - Confirm email address exists and is not already taken, using Parse and email Regex -


i @ part of register process confirm if email given user exists , not taken.

so far, have regex set , customized how want (i limiting user student email address).

- (bool)validateemail:(nsstring *)emailstr { nsstring *emailregex = @"[a-za-z]+\\.[a-za-z]+@[ace]+\\.[tamut]+\\.[edu]"; nspredicate *emailtest = [nspredicate predicatewithformat:@"self matches %@", emailregex];  [self checkemailanddisplayalert];  return [emailtest evaluatewithobject:emailstr];  } 

i throw alert if email not acceptable.

 - (void)checkemailanddisplayalert {  if(![self validateemail:[_email text]]) {       [self.email becomefirstresponder];      // user entered invalid email address     uialertview *alert = [[uialertview alloc] initwithtitle:@"error" message:@"enter valid email address." delegate:self cancelbuttontitle:nil otherbuttontitles:@"ok", nil];     [alert show];   } else {     // user entered valid email address     [self registernewuser];   } } 

if enter email not meet regex requirements, proper alert not shown, , still allowed pass through registration new user. doing wrong?

please don't hold on feedback, new programming , need know, no excuses.

in validateemail method, call checkemailanddisplayalert ([self checkemailanddisplayalert];), , calls validateemail. i'd delete [self checkemailanddisplayalert]; avoid endless loops.

also, try changing regex to

nsstring *emailregex = @"^[a-za-z]+\\.[a-za-z]+@ace\\.tamut\\.edu$"; 

the function check validity like:

- (bool)validateemail:(nsstring *)emailstr {     nserror *error = nil;     nsregularexpression *regex = [nsregularexpression regularexpressionwithpattern:@"^[a-z]+\\.[a-z]+@ace\\.tamut\\.edu$" options:nsregularexpressioncaseinsensitive error:&error];      nsassert(regex, @"unable create regular expression");      nsrange txtrng = nsmakerange(0, emailstr.length);     nsrange matchrng = [regex rangeoffirstmatchinstring:emailstr options:nsmatchingreportprogress range:txtrng];      bool validated = no;      if (matchrng.location != nsnotfound)         validated = yes; // match found      return validated; } 

^ , $ added @ beginning anf end of regex pattern enable whole string search.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -