How can is_int be used to test if a user has entered a number in a form field?

To test if a user has entered a number in a form field, you can use the is_int function in PHP to check if the input is an integer. You can do this by first retrieving the user input from the form field, then using the is_int function to determine if the input is a whole number. If the input is not an integer, you can display an error message to prompt the user to enter a valid number.

$user_input = $_POST['user_input']; // Get user input from form field

if(!is_numeric($user_input) || strpos($user_input, '.') !== false || $user_input < 0 || $user_input != (string)(int)$user_input) {
    echo "Please enter a valid whole number.";
} else {
    // User input is a valid integer
}