Check if absolute URL

JavaScript, String, Browser, Regexp · Oct 20, 2020

Checks if the given string is an absolute URL.

const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);

isAbsoluteURL(''); // true
isAbsoluteURL(''); // true
isAbsoluteURL('/foo/bar'); // false

More like this

  • JavaScript Browser

    Select, traverse and manipulate DOM elements with this collection of JavaScript ES6 snippets.

    Collection · 101 snippets

  • Check if string contains whitespace

    Checks if the given string contains any whitespace characters.

    JavaScript, String · Oct 18, 2020

  • Join URL segments

    Joins all given URL segments together, then normalizes the resulting URL.

    JavaScript, String · Oct 22, 2020

  • Get base URL

    Gets the current URL without any parameters or fragment identifiers.

    JavaScript, String · Jan 3, 2021