IOS Check if email is valid

#import "GTMRegex.h"

//Check if email is valid
//You need to include attached files into your project 
//We are using regular expressions in this method
-(BOOL)isEmailValid:(NSString *)email {
BOOL isValid = YES;
NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
GTMRegex *regex = [GTMRegex regexWithPattern:emailRegEx];
if(([regex matchesString:email]) == YES){
NSLog(@"Registration Form: You have entered valid email address %@", email); 
}
else {
NSLog(@"Registration Form: You have entered INVALID email address %@", email); 
isValid = NO;
}
return isValid;
}

Link: https://github.com/bdewey/ios-minimalist/blob/master/GTM/GTMRegex.m

Comments

Popular posts from this blog

Java : Variables Declaring

Install DNF in RHEL/CentOS 7

SQL Self JOIN