Jerry Stuckle wrote:
lorento wrote:
>$uri = 'http://some-domain-name.org';
if( preg_match(
'/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}'
.'((:[0-9]{1,5})?\/.*)?$/i' ,$uri))
{
echo $uri . ' is a valid url';
}
else
{
echo $uri . ' is NOT a valid url';
}
--
http://www.nusaland.com
http://uk.nusaland.com
rohit wrote:
>>any body can help me to provide the code for URL validate thru PHP
I'm not a regex expert (barely a beginner) - but two problems with this
one.
A uri does not include http or https. That is the protocol being used.
It could be ftp://, for instance.
And this one will fail with some tlds, such as museum.
loreto, nice work.
aside from the mentioned ".museum" and "ftp" (which can be easily edited
in by using the code below) it looks good.
=== UPDATE regex based off of loreto initial post =====
$uri = 'http://some-domain-name.org';
if( preg_match(
'/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}'
.'((:[0-9]{1,5})?\/.*)?$/i' ,$uri))
{
echo $uri . 'oh snap! its a valid URL';
}
else
{
echo $uri . 'Wow i hate you....this is not a valid URL';
}
================================================== =========