title: ASP.NET Regular Expression Validator (Password Strength)
body: <p>I have a validation control that has the following expression:</p>
  
  <pre><code>(?=(.*\\d.*){2,})(?=(.*\\w.*){2,})(?=(.*\\W.*){1,}).{8,}
  </code></pre>
  
  <p>That's a password with at least <strong>2 digits</strong>, <strong>2 alpha characters</strong>, <strong>1 non-alphanumeric</strong> and <strong>8 character minimum</strong>. Unfortunately this doesn't seem to be cross-browser compliant.</p>
  
  <p>This validation works perfectly in Firefox, but it does not in Internet Explorer.</p>
  
  <p><strong><em>A combination of each of your answers results in:</em></strong></p>
  
  <pre><code>var format = "^(?=.{" + minLength + ",})" + 
      (minAlpha &gt; 0 ? "(?=(.*[A-Za-z].*){" + minAlpha + ",})" : "") + 
      (minNum &gt; 0 ? "(?=(.*[0-9].*){" + minNum + ",})" : "") + 
      (minNonAlpha &gt; 0 ? "(?=(.*\\W.*){" + minNonAlpha + ",})" : "") + ".*$";
  
  EX: "^(?=.{x,})(?=(.*[A-Za-z].*){y,})(?=(.*[0-9].*){z,})(?=(.*\W.*){a,}).*$"
  </code></pre>
  
  <p>The important piece is having the (?.{x,}) for the length <strong>first</strong>.</p>