$regex = "((https?|ftp)://)?";
$regex .= "([a-z0-9+!*(),;?&=$_.-]+(:[a-z0-9+!*(),;?&=$_.-]+)?@)?";
$regex .= "([a-z0-9-.]*).([a-z]{2,3})";
$regex .= "(:[0-9]{2,5})?";
$regex .= "(/([a-z0-9+$_-].?)+)*/?";
$regex .= "(?[a-z+&$_.-][a-z0-9;:@&%=+/$_.-]*)?";
$regex .= "(#[a-z_.-][a-z0-9+$_.-]*)?";
$url = 'https://mydomain.com/';
if (preg_match("/^$regex$/i", $url)) {
echo('Enter URL is a valid URL');
}