Re: Regex for email validation

From: Date: Wed, 27 Aug 2008 16:30:04 +0000
Subject: Re: Regex for email validation
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-278786@lists.php.net to get a copy of this message
tedd wrote: >> >>Option 1: /^[_.]+@[a-z0-9-]+\.com$/ >> >>This is probably what you meant: >> >>/^[a-z0-9_.]+@[a-z0-9-]+\.com$/ >> >>/Per Jessen, Zürich > > Which is probably what you meant: > > eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email) > > Email comes in different TLD flavors. Well, I left that for the OP to figure out. Still, your regex is worse - a domain name cannot contain '%'. The only valid characters for a domain name are letters, numbers and a hyphen. Also, maximum length for a domain name is 64 characters, which could/should be checked too. > But, even that still doesn't cover all the possible and legal Unicode > code-points that can exist on both sides of the @ of an email address.. No, they can't. There are no 8-bit characters allowed in an email-address. Check out RFC2821. > tedd@ˆ.com > > is a legal and working email address. If that reads "tedd(at)<space>.com", it might be valid on your system, but not in public. /Per Jessen, Zürich

« previous php.general (#278786) next »