Answers for "js check if url is available"

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

Best way to check if a URL is valid

filter_var($url, FILTER_VALIDATE_URL);

if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
    die('Not a valid!!');
}
Posted by: Guest on October-07-2021

Code answers related to "js check if url is available"

Code answers related to "Javascript"

Browse Popular Code Answers by Language