Check URL validity using JavaScript

Check URL validity using JavaScript
The CheckValidUrl() function takes in an URL and checks whether or not it is valid by verifying it against a regular expression. Works for HTTP, HTTPS and FTP URLs.
function CheckValidUrl(strUrl)

{

        var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
        return RegexUrl.test(strUrl);
}
// Sample use
alert(CheckValidUrl("http://www.geekpedia.com"));

Leave a Reply

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

Back To Top