Files
30-seconds-of-code/snippets/isAbsoluteURL.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

483 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
isAbsoluteURL string,browser,regexp,intermediate 2017-12-31T14:42:45+02:00 2020-10-20T23:02:01+03:00

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);
isAbsoluteURL('https://google.com'); // true
isAbsoluteURL('ftp://www.myserver.net'); // true
isAbsoluteURL('/foo/bar'); // false