Files
30-seconds-of-code/snippets/containsWhitespace.md
2020-09-15 21:52:00 +03:00

444 B

title, tags
title tags
containsWhitespace 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.
const containsWhitespace = str => /\s/.test(str);
containsWhitespace('lorem'); // false
containsWhitespace('lorem ipsum'); // true