Re: email address syntax checker
| From: | Govinda | Date: | Sun, 23 Jan 2011 19:59:12 +0000 |
| Subject: | Re: email address syntax checker | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-310984@lists.php.net to get a copy of this message | ||
> Peter Lind wrote:
> [snip]
>> if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
>> echo "Bad user! Bad user!";
>> }
>>
>> Regards
>> Peter
>
>
> thanks peter... wish I would have known about filter_var before
> writing the other checkers. ;-)
Hi D :-)
I was following along.. also felt pleased to be introduced to filter_var .... and then happened to
see this:
http://us3.php.net/manual/en/function.filter-var.php
the user-contributed note, headed with:
php dot 5 dot leenoble at SPAMMENOTspamgourmet dot net 18-Dec-2009 10:01
"Note that FILTER_VALIDATE_EMAIL used in isolation is not enough for most (if not all) web
based registration forms.
It will happily pronounce "yourname" as valid because presumably the
"@localhost" is implied, so you still have to check that the domain portion of the address
exists.
"
So I am surprised Peter recommended it. (?)
AFAICT, I should stick with what I was using:
$emailPattern = '/^[\w\.\-_\+]+@[\w-]+(\.\w{2,4})+$/i'; //
$emailReplacement = 'theEmailAppearsValid';
$emailChecker = preg_replace($emailPattern, $emailReplacement, $emailToCheck);
if($emailChecker == 'theEmailAppearsValid') {
//--theEmailLooksValid, so use it...
} else {
//--theEmailLooksBad, so do not use it...
}
------------
Govinda