Checks if the given string is an absolute URL.
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
Snippet collection
Working with URLs is an essential skill for web developers. This snippet collection covers all the necessary resources to master URLs in JavaScript.
JavaScript, String
Joins all given URL segments together, then normalizes the resulting URL.
JavaScript, String
Gets the current URL without any parameters or fragment identifiers.
JavaScript, String
Checks if the given string contains any whitespace characters.