Re: What this means "(\w|-)+@\w"? [message #174790 is a reply to message #174784] |
Fri, 08 July 2011 06:42 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma:
|
Senior Member |
|
|
El 07/07/2011 15:58, zhang yun escribió/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 15058#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.)
> I don't know the exactly meaning of "(\w|-)+@\w", could you help me
> figure out its meaning? I'm new to posix standard.
Er... Sorry, this is a Perl-compatible regular expression. The Posix
regexp functions (ereg, eregi...) are deprecated in PHP.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|