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 is url

function isWebUrl(string) {
  let url;
  try {
    url = new URL(string);
  } catch (_) {
    return false;  
  }
  return url.protocol === "http:" || url.protocol === "https:";
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript remove style 
Javascript :: get all keys in json object 
Javascript :: react add inline styles in react 
Javascript :: js reduce a array of straing 
Javascript :: comprobar si un objeto esta vacio javascript 
Javascript :: react fetch custom hook 
Javascript :: javascript list include 
Javascript :: 12 hours to 24 hours javascript 
Javascript :: sort javascript number array with duplicates 
Javascript :: input type search clear event 
Javascript :: js string times 
Javascript :: scroll top js 
Javascript :: electron no resize 
Javascript :: Animated: `useNativeDriver` was not specified. This is a required option and must be explicitly set to `true` or `false` 
Javascript :: jwt token expire time in node js 
Javascript :: javascript regex generator 
Javascript :: chrome.storage.local.remove example 
Javascript :: react and react dom cdn 
Javascript :: how to find largest number in array in javascript 
Javascript :: mongodb $in regex 
Javascript :: react index.jsx example 
Javascript :: scrolltop in javascript 
Javascript :: javascript get current day of month 
Javascript :: javascript intl.numberformat reais 
Javascript :: how to drop collection in mongoose 
Javascript :: to lowercase js 
Javascript :: math floor 
Javascript :: vs code shows bodyparser deprecated 
Javascript :: worker timeout 
Javascript :: js float to percentage 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =