Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

PHP validation/regex for URL

function validateURL($URL) {
      $pattern_1 = "/^(http|https|ftp)://(([A-Z0-9][A-Z0-9_-]*)(.[A-Z0-9][A-Z0-9_-]*)+.(com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(d+))?/?/i";
      $pattern_2 = "/^(www)((.[A-Z0-9][A-Z0-9_-]*)+.(com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(d+))?/?/i";       
      if(preg_match($pattern_1, $URL) || preg_match($pattern_2, $URL)){
        return true;
      } else{
        return false;
      }
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #PHP #URL
ADD COMMENT
Topic
Name
3+7 =