/ Published in: PHP
URL: http://mark.haktstudios.com/
Quick & dirty email address validation function… enjoy. It’s actually a modification of Douglas Lovell’s ( link at bottom of post ) email validation script, except, unlike his, this one actually passes the compliance test that he wrote for it. I essentially just reformatted it to fit my style, moved a couple things around, and fixed an error by adding an additional test that he forgot. This version is safe for PHP4 or higher, and works on servers that do not yet support IPv6
Expand |
Embed | Plain Text
/****************************************************************************** Is email valid?? This function verifies that the email address complies with the following standards: RFC 822 RFC 1035 RFC 2821 RFC 2822 It also ensures that the domain actually resolves. /******************************************************************************/ function e_valid($email) { // get position of the final @ symbol // split up the email address into domain and local parts // determine string length // verify strings aren't too short or too long if ($l_len < 1 || $l_len > 64) return false; if ($d_len < 1 || $d_len > 255) return false; // verify that we don't start or end with a . if ($local[0] == '.' || $local[$l_len-1] == '.') return false; if ($domain[0] == '.' || $domain[$d_len-1] == '.') return false; // verify we don't have two .'s in succession // check for disallowed characters { // check for invalid escape sequences return false; // check for valid DNS entries return false; } // return true, the email is valid. return true; }
Comments
Subscribe to comments
You need to login to post a comment.

But what if a user has an email like [email protected]? I'm not a pro, but i think you count dots as invalid characters there?!?
no I don't, dots are evaluated. Anyway, this snippet is obsolete as of PHP 5.2.x.
filtervar($email, FILTERVALIDATE_EMAIL)
also, I'd like to note that my email address passes validation with this, and it has dots in the first part as well.
Oh, looked at what you might be looking at, it just ensures the email doesn't look like .[email protected] or name..[email protected] because those would be invalid. In other words, it only marks them invalid if they begin with, end with, or have two dots in succession of each other.