All -
I am using the below code (got it online) to validate URLs. However the URL "http://www.yahoo.com?srch=news1&Network=[cnn]" fails to return true because of the brackets in URL variable Network. Is it possible to update the regex to include the brackets too, or should I be looping over the URL variables and remove the brackets?
var webSiteUrlExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
if (webSiteUrlExp.test(url)) {
console.log("true");
return true;
}
else {
console.log("false");
return false;
}