Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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}([-a-zA-Z0-9@:%_+.~#?&//=]*)/g);
  return (res !== null)
};

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

alert(isValidURL(testCase1)); 
Comment

validate URL in javascript

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

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:";
}
Comment

validate url javascript

validateurl
Comment

validate url in javascript

validate url
Comment

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!!');
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: change next js default port 
Javascript :: hex to rgb function 
Javascript :: adding attribute in jquery 
Javascript :: jquery li count in ul 
Javascript :: jquery show password 
Javascript :: toggle class jquery not working 
Javascript :: using multiparty with node js express 
Javascript :: npm verbose stack error 
Javascript :: es6 array sum javascript 
Javascript :: setinterval stop onditional stop 
Javascript :: urlencoded limit 
Javascript :: key value json javascript 
Javascript :: slice javascript string 
Javascript :: vuejs props 
Javascript :: days array in js 
Javascript :: angular generate without spec 
Javascript :: mdn foreach 
Javascript :: how to check hover effect in js 
Javascript :: debounce js 
Javascript :: chart js change axis label 
Javascript :: javascript string to variable 
Javascript :: how to make a clock in js 
Javascript :: how to concatenate strings javascript 
Javascript :: how to change the first Letter to uppercase js 
Javascript :: get element by id like javascript 
Javascript :: jquery on form submit call function 
Javascript :: query string from object js 
Javascript :: boucle for in js 
Javascript :: To get thumbnail image from video file 
Javascript :: .toJSON() in sequelize 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =