Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple PHP snippet to validate a URL using preg_match
<?php
function isValidURL($url){
return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}
// usage
if(!isValidURL($url)){
$message = 'Please enter a valid URL';
echo $message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.