Could someone tell me if this is a bad idea for coding my validation for a password and it is bad? This is for registration for my site. Could you please tell me why and how you would go about it (I am a beginner and at PHP)?

```
$username = $_POST['username'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];

$password_filter1 = '/(?=.*[a-zA-Z0-9]{6})/m';  //Password contains more then 6 char
$password_filter2 = '/(?=.*[A-Z])/m';           //Capital letter
$password_filter3 = '/(?=.*\d)/m';              //A digit

if (!empty($password & $confirm_password)) { 
 if ($password === $confirm_password) { 
  if (preg_match($password_filter1, $password)) {
   if (preg_match($password_filter2, $password)) {
    if (preg_match($password_filter3, $password)) {
     //If everything is true do this
    } else {
     $password_error = "Your password must contain at least 1 number";
    }
   } else {
    $password_error = "You're password must have at least 1 capital letter";
   }
  } else {
   $password_error = "You're password must be at least 6 characters long";
  }
 } else {
  $password_error = "The passwords do not match";
 }
} else {
 $password_error = "You must enter a password";
}

```

The only reason why I am not doing all the filters in 1 `preg_match` is because I would like specific errors.