"regex for email address" Code Answer

2

as featured on: http://github.com/benofsky/dhvalidation

- (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 http://regexkit.sourceforge.net/regexkitlite/ 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: http://verify-email.org/register/levels.html

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}

By Sfavilla on January 2 2022

Answers related to “regex for email address”

Only authorized users can answer the Search term. Please sign in first, or register a free account.