1function validURL(str) {
2 var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
3 '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
4 '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
5 '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
6 '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
7 '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
8 return !!pattern.test(str);
9}
1function isValidURL(string) {
2 var res = string.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
3 return (res !== null)
4};
5
6var testCase1 = "http://en.wikipedia.org/wiki/Procter_&_Gamble";
7
8alert(isValidURL(testCase1));
9