Files
30-seconds-of-code/snippets/containsWhitespace.md
Isabelle Viktoria Maciohsek 2b6f2b1740 Update snippet descriptions & tags
2020-10-18 23:04:45 +03:00

417 B

title, tags
title tags
containsWhitespace string,regexp,beginner

Checks if the given string contains any whitespace characters.

  • 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