Check whether white spaces exist without using trim
<p>I have following code that checks whether date is valid. <a href="http://jsfiddle.net/uzSU6/36/" rel="nofollow">http://jsfiddle.net/uzSU6/36/</a></p>

<p>If there is blank spaces in date part, month part or year part the date should be considered invalid. For this, currently I am checking the length of string before and after <code>trim</code> operation.  It works fine. However is there a better method to check for white spaces? (For example, using <code>===</code> operator)</p>

<pre><code>function isValidDate(s) 
{
var bits = s.split('/');

//Javascript month starts at zero
var d = new Date(bits[2], bits[0] - 1, bits[1]);


if ( isNaN( Number(bits[2]) ) ) 
{
    //Year is not valid number
    return false;
}

if ( Number(bits[2]) &lt; 1 ) 
{
    //Year should be greater than zero
    return false;
}


//If there is unwanted blank space, return false
if  ( ( bits[2].length != $.trim(bits[2]).length ) ||
      ( bits[1].length != $.trim(bits[1]).length ) ||
      ( bits[0].length != $.trim(bits[0]).length ) )
{
    return false;
}



//1. Check whether the year is a Number
//2. Check whether the date parts are eqaul to original date components
//3. Check whether d is valid

return d &amp;&amp; ( (d.getMonth() + 1) == bits[0]) &amp;&amp; (d.getDate() == Number(bits[1]) );

} 
</code></pre>
