Add containsWhitespace snippet

This commit is contained in:
Angelos Chalaris
2020-03-25 12:37:13 +02:00
parent 53d043085d
commit 372da5374e
2 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,17 @@
---
title: containsWhitespace
tags: string,regexp,beginner
---
Returns `true` if the given string contains any whitespace characters, `false` otherwise.
Use `RegExp.prototype.test()` with an appropriate regular expression to check if the given string contains any whitespace characters.
```js
const containsWhitespace = str => /\s/.test(str);
```
```js
containsWhitespace('lorem'); // false
containsWhitespace('lorem ipsum'); // true
```