What are the potential pitfalls of using regex in PHP for data validation?

One potential pitfall of using regex in PHP for data validation is that complex regex patterns can be difficult to understand and maintain. Additionally, regex may not always be the best tool for the job, as it can be inefficient for certain types of validations. To mitigate these issues, consider breaking down complex validations into smaller, more manageable regex patterns or using built-in PHP functions for simpler validations.

// Example of using built-in PHP functions for data validation
$email = "example@example.com";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Email is valid.";
} else {
    echo "Email is invalid.";
}