Validating Domain Names and Websites

If you’re ever in need of a regular expression that will validate every domain name to make sure what the user gave you is valid, you can use Shaun Inman’s Regex. I have to admit, while it’s pretty uber, it’s probably easier just to use cURL to see if the URL is valid.

To accomplish website validation using cURL, there is a snippet of code available on the official PHP homepage: http://ca3.php.net/manual/en/function.curl-exec.php#77167. If the HTTP status is 200 after requesting the website using cURL, the website is valid. If not, you can return an error to the user to verify their URL.