You are here: preg_match() regex to validate URL « PHP Programming Language « IT news, forums, messages
preg_match() regex to validate URL

Posted by deko on 02/12/07 08:57

As I understand it, the characters that make up an Internet domain name can
consist of only alpha-numeric characters and a hyphen
(http://tools.ietf.org/html/rfc3696)

So I'm trying to write regex that will provide a basic url format validation:

starts with http or https (the only 2 prots I'm interested in), is followed by
'://', then ([any alpha-numeric or hyphen] followed by a '.' appearing 1 or more
times), then followed by anything *, and is case-insensitive.

I tried this:

if (preg_match('/^(http|https):\/\/([a-z0-9-]\.+)*/i', $urlString))
{
$valid == true;
}
else
{
$valid == false;
}

but no luck.

Any suggestions welcome...

Thanks in advance.

 

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

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