Skip to content

Instantly share code, notes, and snippets.

@agodin3z
Created October 19, 2020 15:31
Show Gist options
  • Save agodin3z/9ec27b795f20cc99756406a22efea8a8 to your computer and use it in GitHub Desktop.
Save agodin3z/9ec27b795f20cc99756406a22efea8a8 to your computer and use it in GitHub Desktop.
Check if the string is a valid URL
const isValidUrl = (url) => {
const regex = new RegExp(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi);
return url.match(regex);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment