Validating Function:
<?php
function validateURL($url){
$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+$_.-]*)?";
if(preg_match("/^$regex$/", $url))
{
echo $url." =".'<font color="blue">Valid URL</font>';
}
else {
echo $url." =".'<font color="red">Invalid URL</font>';
}
}
?>
2.Validating Function:
<?php
function validateURL($url){
$regex = "|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i";
if(preg_match($regex, $url))
{
echo $url." =".'<font color="blue">Valid URL</font>';
}
else {
echo $url." =".'<font color="red">Invalid URL</font>';
}
}
?>
0 comments:
Post a Comment
Thanks for your valuable Comment