Files
30-seconds-of-code/snippets/isAbsoluteURL.md
2020-09-15 21:52:00 +03:00

426 B

title, tags
title tags
isAbsoluteURL string,browser,url,intermediate

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