FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » What this means "(\w|-)+@\w"?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: What this means "(\w|-)+@\w"? [message #174790 is a reply to message #174784] Fri, 08 July 2011 06:42 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  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
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: upgrade of php & split deprecated = HELP
Next Topic: Re: What is Islam?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 12:32:49 GMT 2024

Total time taken to generate the page: 0.04158 seconds