javascript regex for whitespace or  

javascript, regex

Solution

If you have defined whitespace as 20 spaces, you can do

var input = whitespace + someData;
if(input.indexOf(whitespace) != -1)
{
   //input contains whitespace.
}

There is no need to use regex when you can do without it.

Problem

I am looking for a javascript regex for whitespace. I am checking several different string in a loop and I need to locate the strings that have the big white space in them. The white space string is built in a loop, like this... please read this code as `var whitespace = "&nbsp;"` then the loop just concats more non breaking spaces on it. ``` var whitespace = "&nbsp;" for (var x = 0; x < 20; x++) { whitespace += "&nbsp;" } ``` then it is used later on in a string concat. ``` sometext += whitespace + someData; ``` I need to identify the strings that contain whitespace (20 spaces). Or should I just be doing a `contains(whitespace)` or something similar. Any help is appreciated. Cheers, ~ck in San Diego

Original source