Files
30-seconds-of-code/snippets/isAbsoluteURL.md
2017-12-31 13:15:55 +00:00

16 lines
375 B
Markdown

### isAbsoluteURL
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
```