Share it

Bookmark and Share

Translate

Tuesday, May 31, 2011

0 PHP URL Validation


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."&nbsp;&nbsp;&nbsp;=".'<font color="blue">Valid URL</font>'; 

else {
echo $url."&nbsp;&nbsp;&nbsp;=".'<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."&nbsp;&nbsp;&nbsp;=".'<font color="blue">Valid URL</font>'; 

else {
echo $url."&nbsp;&nbsp;&nbsp;=".'<font color="red">Invalid URL</font>';
}
}
?>


0 comments:

Post a Comment

Thanks for your valuable Comment

 

TechnoTipworld- Tips,Tricks,Technology Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates