You are here: Re: [PHP] Regex help « PHP « IT news, forums, messages
Re: [PHP] Regex help

Posted by Robin Vickery on 08/02/05 17:12

On 8/2/05, Chris Boget <chris.boget@wild.net> wrote:
> I'm trying to validate an email address and for the life of me I
> cannot figure out why the following regex is not working:
>
> $email = "f.lastname@company-di.co.uk";
> $regex =
> "^([a-zA-Z0-9_\.\-\']+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-\']+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";

[a-zA-Z0-9\-\']

You don't escape hyphens like that in a character class. Put it at the
end of the list of characters like this:

[a-zA-Z0-9'-]

Then it'll match your test address.

If you're trying to find out why a regexp isn't working, try
simplifying your test cases until it works. For example:

$email = "f.lastname@company-di.co.uk"; // doesn't work
$email = "lastname@company-di.co.uk"; // doesn't work
$email = "lastname@company-di.com"; // doesn't work
$email = "lastname@company.com"; // works!

I don't suppose this is the place for a rant about the futility of
checking email addresses with a regexp?

-robin

 

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

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