What are the potential pitfalls of using preg_match to validate input format in PHP?

Using preg_match to validate input format in PHP can be prone to errors if the regular expression pattern is not properly constructed. Additionally, it may not be the most efficient method for simple input validation tasks. To mitigate these pitfalls, it is recommended to use built-in PHP functions or libraries specifically designed for input validation.

// Example of using filter_var to validate email input
$email = "test@example.com";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}