What are the advantages of using a single regular expression pattern for password validation in PHP?

When validating passwords in PHP, using a single regular expression pattern can simplify the validation process and ensure consistency. This approach allows for a centralized place to define the password requirements, making it easier to maintain and update the validation logic. Additionally, using a single regular expression pattern can improve code readability and reduce the chances of errors in the validation process.

$password = "Password123";

$pattern = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/";

if (preg_match($pattern, $password)) {
    echo "Password is valid.";
} else {
    echo "Password is invalid.";
}