Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Validate URL With Regex

$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');
}
Source by techsolutionstuff.com #
 
PREVIOUS NEXT
Tagged: #Validate #URL #With #Regex
ADD COMMENT
Topic
Name
2+3 =