What are the advantages and disadvantages of using JavaScript versus PHP to validate input for numbers?

When validating input for numbers, both JavaScript and PHP can be used. JavaScript can provide immediate feedback to users without needing to submit the form, while PHP can provide server-side validation to ensure data integrity. However, JavaScript validation can be easily bypassed by users who disable JavaScript in their browsers, so PHP validation should always be used as a backup. Additionally, PHP validation can prevent malicious attacks such as SQL injection by sanitizing input before processing it.

<?php
$input = $_POST['number'];

if (!is_numeric($input)) {
    echo "Invalid input. Please enter a valid number.";
} else {
    // Process the input
}
?>