What are common pitfalls when using ereg function in PHP for user input validation?

Using the ereg function in PHP for user input validation is not recommended as it is deprecated as of PHP 5.3.0 and removed in PHP 7. Instead, it is recommended to use the preg_match function for regular expression validation in PHP.

// Using preg_match for user input validation
$user_input = "example123";
if(preg_match("/^[a-zA-Z0-9]*$/", $user_input)){
    echo "Input is valid.";
} else {
    echo "Input is invalid.";
}