Files
30-seconds-of-code/snippets/isAbsoluteURL.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

505 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Check if absolute URL string,browser,regexp coffee-phone-tray-2 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