I’m not talking about confirming email, where you have to make sure that the
user owns an email address, but I am talking about a way to confirm that an email entered will probably work
WITHOUT succumbing to regex, AND it’s relatively quick!
[codesyntax
lang=php]
function validate_email($email)
{
$email_parts =
explode("@",$email);
if(count($email_parts)) != 2) { return FALSE; } // You can only have one @
in an email address.
$domain = $email_parts[1];
if(!getmxrr($domain,$array)) { return
FALSE; } // This domain doesn't have any MX Records.
return TRUE; // Everything else is 'valid.'
}
[/codesyntax]
I dunno. It looks nice and neat and simple, but it requires MX lookups and doesn't take
ReplyDeletecare of invalid characters in the user name portion of the email. After all, as it is now, validate_email("o
hai [email protected]") and validate_email("trololol[omg](lol)w/@gmail.com") would pass.
But
I do like the fact that this allows you to validate the domain, something that the regex option doesn't
offer. Add the following if before the return statement and you can be assured that the email passed it at
least looks legit.
if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*$", $email_parts[0])) { return
FALSE; }
Have a look at Ian's email
ReplyDeleteregex compendium. I haven't analyzed MKA's regex in detail, but at first glance it looks like it
would reject a + in the username (which is perfectly valid).
According to the PHP docs for
ReplyDeletegetmxrr(), "This function should not be used for the purposes of address verification." RFC 2821 specifies that if a domain does
not have MX records in the DNS, the hostname itself should be used as the mail exchanger. So you can't
declare that an address is invalid simply because there are no MX records for its domain.
I don't even understand what that means.. OH. Oh. Huh. Well then an proper email
ReplyDeleteverification would try to connect to the server and ask if the user exists. That'd be best. XD (i don't
think that exists in current email implementations, but will in my MSAP protocol, formerly known as reMAP)
Most email Regex does. Its really quite disappointing when I can't signup with a + in
ReplyDeletemy email address for websites. Very disappointing indeed.
About the time we can make the ends meet, somebody moves the ends....
ReplyDeleteIn
these days of austerity in addition to relative stress about incurring debt, many people balk contrary to
the idea of making use of a credit card in order to make acquisition of merchandise or pay for any gift
giving occasion, preferring, instead ju...
I don't think meals have any business being deductible. I'm for
ReplyDeleteseparation of calories and corporations....
Undeniably believe that
which you said. Your favorite justification seemed to be on the internet the easiest thing to be aware of. I
say to you, I definitely get annoyed while people think about worries that they just do not know about. You
managed to ...