Files
30-seconds-of-code/snippets/is-absolute-url.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

22 lines
505 B
Markdown

---
title: Check if absolute URL
tags: string,browser,regexp
cover: coffee-phone-tray-2
firstSeen: 2017-12-31T14:42:45+02:00
lastUpdated: 2020-10-20T23:02:01+03:00
---
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
```