[thelist] Email regex

Edwin Horneij edwin at lanset.com
Wed Feb 26 23:18:00 CST 2003


On Wednesday, February 26, 2003, at 11:40 AM, Chris Evans wrote:

> I use the following regex to validate email:
>
> ^([[:alnum:]][-a-zA-Z0-9_%\.]*)?[[:alnum:]]@[[:alnum:]][-a-zA-Z0-
> 9%\.]*\.[[:alpha:]]{2,}$
>
> When doing some code review, I was asked whether this is the "industry
> standrd" email validation.  Does anybody have a better one, or
> sugestions on how to improve it?  I don't want to go overboard and use
> the 6598 character regex in the back of the O'Reilly "mastering Reg Ex"
> book, but want to make sure I'm validating in a good way.

I don't know if it's better, but I usually use

^[^[:space:]@]+@([[:alnum:]\-])+\.)+[[:alpha:]]{2,6}$

which would allow some weird strings to the right of the "@", but since
even a normal looking email address could be fake, and you never know
what some people will choose as a userid, I figured I'd let it go at
that.




More information about the thelist mailing list