This is my code.
- (BOOL)validateEmail:(NSString*)email
{
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:email];
}
This is the function which i use to validate the email i enter in the textfield. i dont know if what i am doing is correct or wrong. should i be checking it in any other function instead of - (BOOL)textFieldShouldEndEditing if yes please tell me what function i have to use. if my regex or my validation is wrong help me out to get the correct one.
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
BOOL eb;
if (textField.tag == 44) {
eb =[self validateEmail:textField.description];
NSLog(@" %s", eb ? "true" : "false");
if(!eb)
{
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"Please enter correct email id"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];
}
}
return YES;
}