What are the potential pitfalls of using is_numeric() in PHP for price validation?

Using is_numeric() for price validation in PHP can lead to potential pitfalls because it does not account for decimal points or currency symbols. To properly validate prices, it is recommended to use a combination of is_numeric() along with additional checks for decimal points and currency symbols.

function validate_price($price) {
    // Check if the input is numeric
    if (!is_numeric($price)) {
        return false;
    }
    
    // Check if the input contains a decimal point
    if (strpos($price, '.') === false) {
        return false;
    }
    
    // Check if the input contains a currency symbol
    if (preg_match('/[^\d.]/', $price)) {
        return false;
    }
    
    return true;
}

// Example usage
$price = '10.99';
if (validate_price($price)) {
    echo 'Price is valid.';
} else {
    echo 'Price is not valid.';
}