What are some common pitfalls when using the ereg() function in PHP for string validation?

Using the ereg() function in PHP for string validation can lead to security vulnerabilities due to its deprecated status and susceptibility to regex injection attacks. It is recommended to use the preg_match() function instead, which provides more secure and efficient regex matching capabilities.

// Using preg_match() for string validation instead of ereg()
if (preg_match("/^[a-zA-Z0-9]+$/", $input)) {
    // Input is valid
} else {
    // Input is invalid
}