Skip to content

Instantly share code, notes, and snippets.

@yavgel85
Created March 26, 2021 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yavgel85/984f7796dea2bd8515c2cd5d8cb2a9f9 to your computer and use it in GitHub Desktop.
Save yavgel85/984f7796dea2bd8515c2cd5d8cb2a9f9 to your computer and use it in GitHub Desktop.
isAbsoluteURL #js
// Checks if the given string is an absolute URL.
// Use RegExp.prototype.test() to test if the string is an absolute URL.
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
// Examples
isAbsoluteURL('https://google.com'); // true
isAbsoluteURL('ftp://www.myserver.net'); // true
isAbsoluteURL('/foo/bar'); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment