FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


URL regx matching - Please help urgent





imagefree
I am using the following function for validating URLs:

Code:
function check_url($url)
{
   if( filter_var($url , FILTER_VALIDATE_URL ) AND preg_match('~^(https?|ftps?)://(([a-z0-9-]+\.)+[a-z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(:[0-9]+)?(/?|/\S+)$~ix' , $url) )
   {
      return true;
   }
   return false;
   
}


it doesnt validate URLs like http://daily-tech-updates.blogspot.com/ (with - signs and also doesnt validate urls like .co.uk).

Can you please make a correction! I found the regx on the web and used it in my function.
Fire Boar
Code:
function check_url($url)
{
  return filter_var($url, FILTER_VALIDATE_URL) !== false;
}


That's all you need to validate a URL, no need for additional regular expressions unless you want to be more stringent. Also, quick note, the regular expression you have is invalid: ([a-z0-9-]+\.)+ should be ([a-z0-9\-]+\.)+, with a backslash before the hyphen (which would explain why it's not validating URLs with - in their subdomain).
Related topics
Help-Digital Camera selection
Please Help me to configure Outlook Through Proxy
please help quick
Frontpage error please help
Please Help!
Anyone please help me!
64 = 65? Frih$ reward offered! Please help.
VERY URGENT! Please Help Me!
Ok so im wanting to make money from my site please help me
URGENT: Please help - site down due to database error
Name trouble! please help?
Please help about this..
Cant access my DA please help
404 Not Found error was encountered (PLEASE HELP!!!)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.