Skip to main content
File

title: containsWhitespace tags: string,regexp,beginner

TS JS JS

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: string) => /\s/.test(str);
containsWhitespace("lorem"); // false
containsWhitespace("lorem ipsum"); // true