Re: checking if e-mail address and syntax are valid

From: Date: Thu, 26 Apr 2001 03:45:05 +0000
Subject: Re: checking if e-mail address and syntax are valid
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-50422@lists.php.net to get a copy of this message
Problem with this is that many people use '+' in email addresses along with other strange characters (a friend of mine has an apostrophe in her address at General Electric). Bottom line, trying to catch all valid email addresses using a regex is a really ugly thing to try to do. The one shown here will probably work for 95% or more of them though. As an aside, underscores in domain names are illegal (more correctly, underscores in MX-related DNS records are illegal). As such, you don't need to have underscore to the right of the @ sign in this regex. -d Previously, Nikhil Goyal said: > I wrote a similar script of my own... Works fine for me > > function email_valid($email) { > > $pattern="^[0-9a-zA-Z_-]+(\.[0-9a-zA-Z_-]+)*@[0-9a-zA-Z_-]+(\.[0-9a-zA-Z_-]+ > )+$"; > return ereg($pattern, $email); > } > > (returns false if email is not valid, true if it is) -- It's been said that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now thanks to the Internet, we can say that this is not true. -Unknown

« previous php.general (#50422) next »