Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #2471
| From | "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: What this means "(\w|-)+@\w"? |
| Date | 2011-07-08 08:42 +0200 |
| Organization | http://alvaro.es/ |
| Message-ID | <iv68tf$fla$1@dont-email.me> (permalink) |
| References | <b2cdc780-b6d4-4b6e-a01e-444a616c0fe0@r18g2000vbs.googlegroups.com> |
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/2515058#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
--
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What this means "(\w|-)+@\w"? zhang yun <bigzhangyun@gmail.com> - 2011-07-07 06:58 -0700
Re: What this means "(\w|-)+@\w"? Michael Fesser <netizen@gmx.de> - 2011-07-07 17:39 +0200
Re: What this means "(\w|-)+@\w"? Eli the Bearded <*@eli.users.panix.com> - 2011-07-07 18:23 +0000
Re: What this means "(\w|-)+@\w"? Michael Fesser <netizen@gmx.de> - 2011-07-07 21:12 +0200
Re: What this means "(\w|-)+@\w"? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-07-07 21:12 +0200
Re: What this means "(\w|-)+@\w"? Eli the Bearded <*@eli.users.panix.com> - 2011-07-08 06:05 +0000
Re: What this means "(\w|-)+@\w"? "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-07-08 08:42 +0200
Re: What this means "(\w|-)+@\w"? Sandman <mr@sandman.net> - 2011-08-02 10:06 +0200
Re: What this means "(\w|-)+@\w"? "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-08-02 11:50 +0200
Re: What this means "(\w|-)+@\w"? "Peter H. Coffin" <hellsop@ninehells.com> - 2011-08-02 07:56 -0500
Re: What this means "(\w|-)+@\w"? Eli the Bearded <*@eli.users.panix.com> - 2011-08-02 20:53 +0000
Re: What this means "(\w|-)+@\w"? "Peter H. Coffin" <hellsop@ninehells.com> - 2011-08-03 08:32 -0500
Re: What this means "(\w|-)+@\w"? "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-08-03 10:55 +0200
Re: What this means "(\w|-)+@\w"? "Peter H. Coffin" <hellsop@ninehells.com> - 2011-08-03 08:46 -0500
Re: What this means "(\w|-)+@\w"? Sandman <mr@sandman.net> - 2011-08-03 00:21 +0200
Re: What this means "(\w|-)+@\w"? Eli the Bearded <*@eli.users.panix.com> - 2011-08-03 07:45 +0000
Re: What this means "(\w|-)+@\w"? Sandman <mr@sandman.net> - 2011-08-03 10:02 +0200
Re: What this means "(\w|-)+@\w"? Eli the Bearded <*@eli.users.panix.com> - 2011-08-05 00:05 +0000
csiph-web