Files
30-seconds-of-code/snippets/isAbsoluteURL.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

18 lines
431 B
Markdown

---
title: isAbsoluteURL
tags: string,utility,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.
```js
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
```
```js
isAbsoluteURL('https://google.com'); // true
isAbsoluteURL('ftp://www.myserver.net'); // true
isAbsoluteURL('/foo/bar'); // false
```