Code Library
Home Submit Free Hosting Link To Us Contacts

CGI RegExp to validate URL syntax

CGI RegExp to validate URL syntax CGI CGI RegExp to validate URL syntax Download (.zip)



sub validateUrl {
  my($strUrl) = shift;
  return
  $strUrl =~ m!(http:|https:|ftp:)//([A-z\d]+)\:([A-z\d]+)\@([A-z\d\-\.]+\.)+[A-z]!i ||
  $strUrl =~ m!^(http:|https:|ftp:)//([A-z\d\-\.]+\.)+[A-z]!i ||
  $strUrl=~ m!^(http:|https:|ftp:)//(\d){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3}!i ? 1 : 0;
}

$url = 'http://www.example.com/test.html';
$res = validateUrl($url);






Tatet