Answers for "javasriopt is valur url"

1

Check if a JavaScript string is a URL

function isValidURL(string) {
  var res = string.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
  return (res !== null)
};

var testCase1 = "http://en.wikipedia.org/wiki/Procter_&_Gamble";

alert(isValidURL(testCase1));
Posted by: Guest on December-02-2020
0

javascript is url

function isWebUrl(string) {
  let url;
  try {
    url = new URL(string);
  } catch (_) {
    return false;  
  }
  return url.protocol === "http:" || url.protocol === "https:";
}
Posted by: Guest on April-14-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language