You are here: Re: This one better I think. (Re: Regex help for email) « PHP Programming Language « IT news, forums, messages
Re: This one better I think. (Re: Regex help for email)

Posted by Steve on 10/22/07 16:53

"AnrDaemon" <anrdaemon@freemail.ru> wrote in message
news:1979714934.20071021180056@freemail.ru...
> Greetings, gezerpunta.
> In reply to Your message dated Thursday, October 18, 2007, 18:59:31,
>
> <?php
>
> $s = 'celo@tum.com, "mnp test" <celo@tum.com>,"test testt" <otur@par.com>,
> sett@tttt.com,test@twest.com';
>
> if(preg_match_all('#(?:^|[\s\,])<?([0-9A-Za-z\_]+(?:[\-\.][0-9A-Za-z\_]+)*\@[0-9A-Za-z]+(?:[\.\-\_][0-9A-Za-z]+)+)>?#xi',
> $s, $ta))
> {
> var_export($ta[1]);
> }

of course you would. however, notice that whatever your prowess at regex,
you lack understanding of the basic email conventions explained in the
rfc(s). your preg doesn't allow for atomic account names. ;^)

hmmmm...this *does* (and then some).

function isEmail($email)
{
if (!$email){ return false; }
$pattern =
"/^((\"[^\"]*?\")|([^\(\)\<\>\@\,\;\:\\\"\[\]\s\*\/]+))@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$/si";
return preg_match($pattern, $email);
}

the pattern above simply needs to be applied to the entire string, and you
get what you want.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация