Skip to content

Instantly share code, notes, and snippets.

@msteckyefantis
Last active October 15, 2018 16:56
Show Gist options
  • Save msteckyefantis/0890bcadb96406da4907275da13e3d77 to your computer and use it in GitHub Desktop.
Save msteckyefantis/0890bcadb96406da4907275da13e3d77 to your computer and use it in GitHub Desktop.
getIfValueIsUrl
function getIfValueIsUrl( value ) {
const urlRegex = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
const valueIsUrl = !!value.match( urlRegex );
return valueIsUrl;
}
// inspired by https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
@msteckyefantis
Copy link
Author

msteckyefantis commented Oct 15, 2018

note: this code has not been thoroughly tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment