Advertise with us

Sponsors

Regular Expression Details

This expression matches email addresses, and checks that they are of the proper form. It checks to ensure the top level domain is between 2 and 4 characters long, but does not check the specific domain against a list (especially since there are so many of them now).

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: special character in domain nameName: zikwagDate: 7/17/2009 2:45:41 PMComment: how can i modify this regex so that the address xyz@its.j&j.com bypass validation rules

Title: special character in domain nameName: zikwagDate: 7/17/2009 2:06:30 PMComment: how can i modify this regex so that the address xyz@its.j&j.com bypass validation rules

Title: Further refinedName: cottsakDate: 1/4/2007 11:09:29 PMComment: the following is modded further from the comments on this page. it additionally:
- does not allow underscore in the domain name
- does not allow hyphen at start or end of domain name (sub-domains included)
also, i have expand the \w change so that it's explicit, irrespective of engine flavour
the only other thing i didn’t factor (that i could think of) was minimal number of characters for a domain. generally this is >= 2 but for sub-domains it may be 1 so i left it. it would also make the expression a lot more complicated.
^[-a-zA-Z_0-9.]+@([a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z0-9])?.)+[a-zA-Z]{2,4}$

Title: \. inside a character class does not mean .Name: Udo GüngerichDate: 8/14/2006 2:42:10 AMComment: Inside character classes . does not have a special meaning, so you do not need to escape it!
Regards,
Udo
P.S.: [[:alnum:]_-\.] must of course be [-[:alnum:]_\.] else the dash tries to be a range and fails ;)

Title: [\w] is not a character class according to Perl 5.8.6Name: Udo GüngerichDate: 8/14/2006 2:37:23 AMComment: So [\w-\.] is probably better written as [[:alnum:]_-\.] (with POSIX character classes)
Regards,
Udo

Title: little improvementName: JockerDate: 7/10/2006 11:25:32 AMComment: ^[\w-\.]+@(?:[\w-]+\.)+[a-zA-Z]{2,4}$
a slightly better version: this one does not capture part of the domain, does not allow numbers in the regional code

Title: Incompatible with internet standardsName: Josh JoreDate: 2/23/2004 11:34:04 AMComment: The expression does not account for whitespace or quoting in the mailbox portion of the address and neglects to handle quoted domains.

Title: FLANTUSName: SGSGSDate: 1/22/2004 5:14:13 PMComment: THANKS A LOT! EXELLENT SITE ESPECIALLY TO THE STARTERS. IT IS ALSO GREAT FOR LOOKUP.
THANKS