Created
March 26, 2021 11:35
-
-
Save yavgel85/984f7796dea2bd8515c2cd5d8cb2a9f9 to your computer and use it in GitHub Desktop.
isAbsoluteURL #js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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