validate

Validate URL by regular expression

This is how you can validate an URL by examining the pattern.

<?php
function  validateURL($url) {
 
$pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&amp;?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/';
 return
preg_match($pattern, $url);
}
?>

Or from Drupal 6

/**
* Verify the syntax of the given URL.
*
* This function should only be used on actual URLs.