Wednesday, December 26, 2012

Regular expresion to validate URL

var url = value.v_url;

var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

if (pattern.test(url)) {
        content+='<a href="'+value.v_url+'" target="_blank">'; //  Url is valid
}
else{
        console.log("invalid url");
}