What potential pitfalls can arise when using preg_match for form validation in PHP?

One potential pitfall when using preg_match for form validation in PHP is that the regular expression used may not accurately validate the input data as intended. To solve this issue, it is important to carefully craft the regular expression to match the specific format or pattern required for validation.

// Example of using preg_match with a carefully crafted regular expression for email validation
$email = "example@example.com";

if (preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/", $email)) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}