I am checking validation of email but not done following are my code. Please tell me what the issue behind it.
-(BOOL) validateEmail: (NSString *) candidate {
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:candidate];
}
-(BOOL)RagistationValidation{
if ([_txtmail.text isEqualToString:@""] ) {
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Wrong Email Id" message:@"Please enter Emailid" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
}else if ([self validateEmail:_txtmail.text]){
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Wrong Email Id" message:@"Please enter valid Emailid" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
}
Please help me.
Your Regex Should be like this, So please replace it for email validation
FOR CHECKING