Try this now:

PHP Code: 
<?php
function addnvalidateurls($url){
// Modified By: Soft2050
if (!preg_match("@^[hf]tt?ps?://@"$url)) {
        
$url "http://" $url;
}
$pattern '@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@';
return 
preg_match($pattern$url);


$result addnvalidateurls('google.com');
echo 
'<script language="javascript">';
if (
$result == 1)
echo 
"alert('Yes! The given url is validated')";
else {
echo 
"alert('No! the given url seems to be not working')";
}
echo 
'</script>';
?>
Regex Code: http://snipplr.com/view/36992/improv...on-with-regex/

Or have a search for some premade regex using google or you can code yourself if you are good at it