Email Address Validation

//returns YES if checked string is email formatted, or NO

-(BOOL) validateEmail:(NSString*) string {
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:string];
}

1 comment:

  1. Nice coding, i am very surprised after reading this one.

    ReplyDelete