Checking for bunch of whitespaces in javascript to prevent blank data being sent and trimming the intermediate spaces
<p>I'm a bit confused as to how to solve this problem. Seems standard and commonly occurring but couldn't find anything worthwhile. I have an HTML textarea and a textbox for input. I want to validate the following:</p>

<ol>
<li>The user shouldn't be allowed to enter a bunch of white spaces in the textarea - so if 15 characters is the minimum 16 whitespace characters only shouldn't count towards valid data. A simple char count won't detect this. </li>
<li>One can enter 16 whitespaces and one letter, but that is still invalid data! Anyway to check to check the validity here (it should basically be counted as 2 characters as per below point)?</li>
<li>Trimming unnecessary whitespaces - i.e., if someone enters a character/word and follows it up by 10 whitespaces then another and then a character and another set of whitespaces, I'd like them to be trimmed to a single white space. Just like what happens when you enter an answer/new question on SO. If you enter a bunch of whitespaces it will automatically trim it. I tried searching around but nothing for whitespace specific.</li>
</ol>

<p>Intuitively if I can just get solution to #3 to work I guess it could automatically feed it into a char counter function and it would be valid, correct?</p>

<p>Any ideas how to go about doing this? jQuery or javascript are both acceptable :)</p>
