Answers for "js how to see if url contains a string"

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

check-if-a-javascript-string-is-a-url

const isUrl = string => {
      try { return Boolean(new URL(string)); }
      catch(e){ return false; }
  }
Posted by: Guest on August-31-2021

Code answers related to "js how to see if url contains a string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language