Files
30-seconds-of-code/snippets/isAbsoluteURL.md
Isabelle Viktoria Maciohsek caa67e2a49 Update snippet descriptions
2020-10-20 23:02:01 +03:00

19 lines
407 B
Markdown

---
title: isAbsoluteURL
tags: string,browser,regexp,intermediate
---
Checks if the given string is an absolute URL.
- Use `RegExp.prototype.test()` 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
```