Skip to content

Instantly share code, notes, and snippets.

@beakr
Created April 6, 2012 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beakr/2321854 to your computer and use it in GitHub Desktop.
Save beakr/2321854 to your computer and use it in GitHub Desktop.
Telling if the entire string consists of an item (whitespace in this case)
var re = /^\s+$/;
/*
* ^ - start of string
* \s - anything whitespace
* + - 1 or more
* $ - the end of the string
*/
if (" ".match(re)) {
alert("The string is all whitespace!");
}
//=> The string is all whitespace!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment