Reputation: 356
Here is code I have for a url validation function in CI, and this is the callback function
function valid_url($facebook)
{
$pattern = "/^((ht|f)tp(s?)\:\/\/|~/|/)?([w]{2}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?/";
if (!preg_match($pattern, $facebook))
{
return FALSE;
}
return TRUE;
}
I'm getting this error
Message: preg_match() [function.preg-match]: Unknown modifier '|'
Upvotes: 1
Views: 2121
Reputation: 2934
Try this
function validate_url($url) {
$data = trim($url);
$data = stripslashes($url);
$data = htmlspecialchars($url);
return $url;
// check address syntax is valid or not(this regular expression also allows dashes in the URL)
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) {
return FALSE;
} else {
return TRUE;
}
}
$check = validate_url($url);
Upvotes: 1