IOS Email Validation

Email authentication in iPhone programming can be performed using the RegexKitLite (iOS2.0), NSPredicate (iOS 3.0 and later), and NSRegularExpression (iOS 4.0) NSRegularExpression . But can anyone say what is the advantage of one over the other and which is the best option for checking the three indicated.

+4
source share
7 answers

I think it depends a lot on the minimum version of iOS that the application will support, and if there is a built-in class that will do the job, use it. As you hinted, you would use some kind of third-party structure to support older versions.

Right now, I would use NSPredicate or NSRegularExpression , both of which are supported from iOS 4 onwards, which is likely to be the minimum supported version for new iOS apps, if not iOS 5.

Useful post .

+1
source

I always use NSPredicate ... and it works great

 NSString *emailid = emailField.text; NSString *emailRegex = @"[A-Z0-9a-z._%+-] +@ [A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; BOOL myStringMatchesRegEx=[emailTest evaluateWithObject:emailid]; 
+12
source

My answer has been reorganized from a great solution given in this link .

 ///Returns YES (true) if EMail is valid +(BOOL) IsValidEmail:(NSString *)emailString Strict:(BOOL)strictFilter { NSString *stricterFilterString = @"[A-Z0-9a-z._%+-] +@ [A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSString *laxString = @" .+@. +\\.[A-Za-z]{2}[A-Za-z]*"; NSString *emailRegex = strictFilter ? stricterFilterString : laxString; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; return [emailTest evaluateWithObject:emailString]; } 
+8
source
 - (BOOL)validateEmail:(NSString *)emailStr { NSString *emailRegex = @"[A-Z0-9a-z._%+] +@ [A-Za-z0-9.]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; return [emailTest evaluateWithObject:emailStr]; } On Button Click : if (![self validateEmail:[txtEmail text]]) { alertValidator.message = @"Please Enter Valid Email Address !"; [alertValidator show]; txtEmail.text = @""; [txtEmail becomeFirstResponder]; } 
+3
source

I think the best option, hands down, Mailgun is a free email validation API . I wrote a simple objective-C shell for it:

https://github.com/benzguo/BZGMailgunEmailValidation

 BZGMailgunEmailValidator *validator = [BZGMailgunEmailValidator validatorWithPublicKey:YOUR_PUBLIC_KEY]; [validator validateEmailAddress:self.emailFieldCell.textField.text success:^(BOOL isValid, NSString *didYouMean) { // Validation succeeded } failure:^(NSError *error) { // Validation failed }]; 

If there is a connection error, the validator returns to the regular expression check.

If you still want to check your email using regex, check:

http://www.regular-expressions.info/email.html

https://wiki.mozilla.org/TLD_List

+2
source

full email check. try it

 - (BOOL)validateEmailWithString:(NSString*)checkString { NSString *laxString = @" .+@ ([A-Za-z0-9-]+\\.)+[A-Za-z]{2}[A-Za-z]*"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", laxString]; return [emailTest evaluateWithObject:checkString]; } 
0
source

how to create email id and password check in ios

Hurry up, just for a simple verification of the email id, check that after the useful code.

 - (IBAction)actLogin:(id)sender { if([self validateEmailWithString:userNameText.text]==YES) { NSLog(@"valid email"); if (passWordText.text.length>6) { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:userNameText.text forKey:@"username"]; [defaults setObject:passWordText.text forKey:@"password"]; [defaults setObject:@"YES" forKey:@"islogin"]; [defaults synchronize]; NSLog(@"Login is Successfully !!"); } } else { NSLog(@"invalid email and password"); } } 

So, I hope that helps you. Thanks...

-1
source

Source: https://habr.com/ru/post/1386471/


All Articles