Re: What this means "(\w|-)+@\w"? [message #174995 is a reply to message #174790] |
Tue, 02 August 2011 08:06 |
Sandman
Messages: 32 Registered: August 2011
Karma:
|
Member |
|
|
In article <iv68tf$fla$1(at)dont-email(dot)me>,
"Álvaro G. Vicario" <alvaro(dot)NOSPAMTHANX(at)demogracia(dot)com(dot)invalid>
wrote:
>> I have some problems in regular expression, here is code :
>> function is_email($e_name)
>> {
>> $arr = array("ac","com","net","org","edu","gov","mil","ac\.cn",
>> "com\.cn","edu\.cn","net\.cn","org\.cn");
>> $str = implode("|",$arr);
>> $reg ='/^[0-9a-zA-z](\w|-)+@\w+\.('.$str.')$/';
>> //echo $reg;
>> if(preg_match($reg,strtolower($e_name)))
>> return strtolower($e_name);
>> else
>> return false;
>> }
>
> As already mentioned, it's a terrible way to validate e-mails. Among
> other omissions, it discards like a hundred valid top level domains:
>
> http://en.wikipedia.org/wiki/List_of_Internet_TLDs
>
> If you are interested in the subject, I suggest you read this forum entry:
>
> http://stackoverflow.com/questions/2514810/php-email-validation-question/25 150
> 58#2515058
>
> I'd say the best options is to write your own simple and permissive
> expression, although you can also use a reliable third-party library and
> keep it updated. (I found
> http://code.google.com/p/php-email-address-validation/ but I have no
> references about it.)
What's wrong with the PHP built in email validator?
<?
if (filter_var($email, FILTER_VALIDATE_EMAIL)){
# Do fancy stuff, such as sending fancy email!
}
?>
--
Sandman[.net]
|
|
|