Files
30-seconds-of-code/snippets/isAbsoluteURL.md
Angelos Chalaris 02a5c628e9 Add isAbsoluteURL
2017-12-31 14:42:45 +02:00

376 B

isAbsoluteURL

Returns true if the given string is an absolute URL, false otherwise.

Use a regular expression to test if the string is an absolute URL.

const isAbsoluteURL = str =>  /^[a-z][a-z0-9+.-]*:/.test(str);
isAbsoluteURL('https://google.com'); // true
isAbsoluteURL('ftp://www.myserver.net'); // true
isAbsoluteURL('/foo/bar'); // false