How does using preg_match compare to other methods for validating input in PHP, such as is_numeric()?

When validating input in PHP, using preg_match allows for more flexibility and control compared to functions like is_numeric(). preg_match allows for the use of regular expressions to define specific validation patterns, while is_numeric() simply checks if a value is a number. This means preg_match can be used to validate a wider range of input formats beyond just numbers.

// Example of using preg_match to validate an email address
$email = "example@example.com";

if(preg_match("/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/", $email)) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}