Add isAbsoluteURL

This commit is contained in:
Angelos Chalaris
2017-12-31 14:42:45 +02:00
parent 04a804bfb5
commit 02a5c628e9
2 changed files with 16 additions and 0 deletions

15
snippets/isAbsoluteURL.md Normal file
View File

@ -0,0 +1,15 @@
### 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
```