- (BOOL) isValidEmail:(NSString *) email {
errorMessage = [NSMutableString stringWithString: @""];
BOOL validEmail = YES;
NSString *emailRegex = @"[a-zA-Z0-9.\\-_]{2,32}@[a-zA-Z0-9.\\-_]{2,32}\[A-Za-z]{2,4}";
NSPredicate *regExPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
validEmail = [regExPredicate evaluateWithObject:email];
if (!validEmail) {
errorMessage = [NSMutableString stringWithString:@"Invalid Email"];
validEmail = NO;
NSLog(@"Invalid Email");
}
if ([email length] > 30) {
errorMessage = [NSMutableString stringWithString:@"Very Long Email"];
validEmail = NO;
NSLog(@"Very Long Email");
}
if ([email length] == ZERO_LENGTH) {
errorMessage = [NSMutableString stringWithString:@"Please type valid email id"];
validEmail = NO;
NSLog(@"Please type valid email id");
}
return validEmail;
}
0 comments:
Post a Comment