Answers for "Best way to check if a URL is valid"

PHP
-1

javascript determine if string is valid url

function isValidHttpUrl(string) {
  let url;
  
  try {
    url = new URL(string);
  } catch (_) {
    return false;  
  }

  return url.protocol === "http:" || url.protocol === "https:";
}
Posted by: Guest on February-05-2021
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 "Best way to check if a URL is valid"

Browse Popular Code Answers by Language