Files
30-seconds-of-code/snippets/isAbsoluteURL.md
Isabelle Viktoria Maciohsek 821f442bec Remove url tag
2020-10-18 14:19:29 +03:00

19 lines
422 B
Markdown

---
title: isAbsoluteURL
tags: string,browser,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
```