How can PHP developers ensure that only 2-3 digit numbers are accepted as input variables to prevent SQL injection?

To ensure that only 2-3 digit numbers are accepted as input variables to prevent SQL injection, PHP developers can use regular expressions to validate the input. By checking if the input matches the pattern of a number with 2-3 digits, developers can prevent malicious SQL injection attempts.

$input = $_POST['input'];

if (preg_match('/^\d{2,3}$/', $input)) {
    // Input is a valid 2-3 digit number, proceed with SQL query
} else {
    // Invalid input, handle error or reject the input
}