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

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 :: image react 
Javascript :: uuid in node js 
Javascript :: react toastify is not working 
Javascript :: dropzone add download button addedfile 
Javascript :: foreach loop in nodejs 
Javascript :: bcrypt 
Javascript :: how to put space in between characters javascript 
Javascript :: react eslint prettier 
Javascript :: moment format yyyy-mm-dd 
Javascript :: Duplicate empty header occur in datatable when enabling scrollX or scrollY when using Google Chrome 
Javascript :: redux update item in array 
Javascript :: loop node list 
Javascript :: create object from array 
Javascript :: how to use graphql api in react 
Javascript :: nodejs return code 
Javascript :: react detect page width 
Javascript :: axios forward 
Javascript :: node require fs not found 
Javascript :: deploy react to aws 
Javascript :: post request javascript 
Javascript :: how can we open page on new tab in angular or js or typescript 
Javascript :: try and catch express 
Javascript :: convert nuber into string react js 
Javascript :: get milliseconds since epoch for 12am today javascript 
Javascript :: see vuex values productin 
Javascript :: convert array object to string javascript 
Javascript :: react native gif dont work 
Javascript :: java script strict tag 
Javascript :: react native data map is not a function 
Javascript :: how to use useref hook in react 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =