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
1function isValidHttpUrl(string) {
2 let url;
3
4 try {
5 url = new URL(string);
6 } catch (_) {
7 return false;
8 }
9
10 return url.protocol === "http:" || url.protocol === "https:";
11}