Skip to main content
CalcHive

Regex for Whitespace Only

Matches strings that contain only whitespace characters (spaces, tabs, newlines). Useful for empty input detection.

Pattern

/^\s+$/

Pattern Breakdown

TokenExplanation
^Start of string
\s+One or more whitespace characters
$End of string

Test Examples

InputMatch?
Match
Match
hello No match
No match

Common Use Cases

  • Empty input validation
  • Trimming detection
  • Form field checking

Variations

^\s*$

Allows empty string too

Want to test this pattern with your own data?

Open the Regex Tester