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 :: export apk react native 
Javascript :: date time js 
Javascript :: count number of each element in array javascript 
Javascript :: nodejs csv to json from link 
Javascript :: js named parameters 
Javascript :: Reached heap limit Allocation failed - JavaScript heap out of memory nodejs 
Javascript :: js window location relative path 
Javascript :: imdb-api 
Javascript :: regexp object javascript 
Javascript :: js array add element 
Javascript :: js validate phone number 
Javascript :: generating random number in javascript 
Javascript :: post message in iframe javascript 
Javascript :: access selected option in jquery 
Javascript :: remove special characters from string 
Javascript :: get object key name in js 
Javascript :: sh: /Users/ahmedqadri/Desktop/Projects/stockNotesAPP-frontend/node_modules/.bin/react-scripts: Permission denied 
Javascript :: mongoose get document 
Javascript :: javascript url check 
Javascript :: bulk create in sequelize 
Javascript :: how to sort an array of objects by two fields in javascript 
Javascript :: remove double quotes from json array javascript 
Javascript :: javascript how to check if array is empty 
Javascript :: Animated: `useNativeDriver` was not specified. This is a required option and must be explicitly set to `true` or `false` 
Javascript :: select dropdown value using jquery 
Javascript :: jquery fadeout and remove 
Javascript :: firebase order by key descending 
Javascript :: mongodb $in regex 
Javascript :: how to scroll to an element javascript react 
Javascript :: javascript two digits number 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =