WordPress provides a helpful function called is_email() which checks if a given email address is valid. Is there a similar function available to check if a URL is valid?

I tried is_url() but that was just wishful thinking on my part.

Ref: http://codex.wordpress.org/Function_Reference/is_email

7

Use the native php function Filter Validator

if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
    die('Not a valid URL');
}

Leave a Reply

Your email address will not be published. Required fields are marked *