An0r4k An0r4k - 1 month ago 5x
Objective-C Question

Regex for email address

Can someone show me a sample RegEx for an email address and how to use in in Objective-C?

Looking for something that fits:



As featured on:

- (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];

Or add the to your project and do the regex yourself like above.

Also to reply to the issue of checking if an e-mail address is actually real, not just works with regex you could use some service like:

Please note this answer doesn't take into account the newer length TLDs such as .online; to include those update the final {2,4} to be {2,63}