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

javascript url check

const isAbsoluteUrl = url => /^[a-z][a-z0-9+.-]*:/.test(url);

// Example
isAbsoluteUrl('https://1loc.dev');          // true
isAbsoluteUrl('https://1loc.dev/foo/bar');  // true
isAbsoluteUrl('1loc.dev');                  // false
isAbsoluteUrl('//1loc.dev'); 
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

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

  const isUrl = string => {
      try { return Boolean(new URL(string)); }
      catch(e){ return false; }
  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: material ui input placeholder color 
Javascript :: jquery only on mobile 
Javascript :: jquery validation on button click 
Javascript :: aos react 
Javascript :: js number add zero before 
Javascript :: has decimal javascript 
Javascript :: como remover uma variável de um json 
Javascript :: ionic 4 how to iterate json object in view 
Javascript :: equivalent of useHistory in react 
Javascript :: Access-Control-Allow-Origin 
Javascript :: MIN_SAFE_INTEGER 
Javascript :: Laravel csrf token mismatch for ajax POST Request 
Javascript :: how to remove trailing space in string js 
Javascript :: loop through object and get a certain values 
Javascript :: convert number to k m b javascript 
Javascript :: moment calculate duration 
Javascript :: login to discord using token 
Javascript :: firebase auth sign out javascript 
Javascript :: sweet alert 2 do action on confirm 
Javascript :: append to array check if exists javascript 
Javascript :: how to get name array value checked in jquery 
Javascript :: ready function javascript 
Javascript :: Get Substring between two characters using javascript 
Javascript :: javascript change image src 
Javascript :: js round to nearest thousand 
Javascript :: reaact native expo jsx 
Javascript :: get url query params js 
Javascript :: js remove after character 
Javascript :: take only int part of number js 
Javascript :: javascript regex for usernames 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =