title: PHP regex for password validation
body: <p>I not getting the desired effect from a script. I want the password to contain A-Z, a-z, 0-9, and special chars.</p>
  
  <ul>
  <li>A-Z</li>
  <li>a-z </li>
  <li>0-9 >= 2</li>
  <li>special chars >= 2</li>
  <li>string length >= 8</li>
  </ul>
  
  <p>So I want to force the user to use at least 2 digits and at least 2 special chars. Ok my script works but forces me to use the digits or chars back to back. I don't want that. e.g. password testABC55$$ is valid - but i don't want that. </p>
  
  <p>Instead I want test$ABC5#8 to be valid. So basically the digits/special char can be the same or diff -> but must be split up in the string.</p>
  
  <p>PHP CODE:</p>
  
  <pre><code>$uppercase = preg_match('#[A-Z]#', $password);
  $lowercase = preg_match('#[a-z]#', $password);
  $number    = preg_match('#[0-9]#', $password);
  $special   = preg_match('#[\W]{2,}#', $password); 
  $length    = strlen($password) &gt;= 8;
  
  if(!$uppercase || !$lowercase || !$number || !$special || !$length) {
    $errorpw = 'Bad Password';
  </code></pre>