How can PHP be used to enforce specific rules for input validation, such as requiring a number and allowing optional letters?

To enforce specific rules for input validation in PHP, such as requiring a number and allowing optional letters, you can use regular expressions. Regular expressions allow you to define patterns that the input must match. You can use the preg_match function in PHP to check if the input matches the specified pattern.

$input = "123abc"; // Input to validate
$pattern = "/^\d+[a-zA-Z]*$/"; // Pattern to require a number and allow optional letters

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