title: Javascript validation - Min/Max number of characters AND must contain number
body: <p>I have the following problem:</p>
  
  <p>I need to validate an input (password field) with Javascript / jQuery</p>
  
  <p>The rules are: </p>
  
  <p>it must be 8 to 32 characters
  it must contain letters AND at least one number</p>
  
  <p>So my logic is the following but I can't seem to be able to implement it</p>
  
  <p>be 8 to 32 </p>
  
  <pre><code>if it's NOT 8 to 32 characters and doesn't have numbers
  {
      jQuery('#passwordfield').addClass('error');
  }
  </code></pre>
  
  <p>I tried the following (just with 0 as number, for test purposes) </p>
  
  <pre><code>if(((jQuery('#passwordfield').val().length &lt;= 7) || (jQuery('#passwordfield').val().length &gt;= 33)) &amp;&amp; ((jQuery('#passwordfield').val().indexOf("0") == -1)))
  {
       jQuery('#passwordfield').addClass('error');
  }
  </code></pre>
  
  <p>The problem with the above code is that it returns true if you type enough characters (8 to 32) and NOT contain a number since the first part of the &amp;&amp; is true</p>