Skip to content

Instantly share code, notes, and snippets.

@ir3ne
Created July 10, 2021 09:56
Show Gist options
  • Save ir3ne/01e46da4cefb58a637dc8bd0baa5d0b6 to your computer and use it in GitHub Desktop.
Save ir3ne/01e46da4cefb58a637dc8bd0baa5d0b6 to your computer and use it in GitHub Desktop.
function checkUrl(url) {
const urlPattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i')
return urlPattern.test(url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment