What is the difference between using ereg and preg_match in PHP for regex validation?

The main difference between using `ereg` and `preg_match` in PHP for regex validation is that `ereg` is a POSIX regular expression function that is now deprecated in PHP, while `preg_match` is the recommended function to use for regular expression matching. `preg_match` supports Perl-compatible regular expressions (PCRE) and provides more features and flexibility compared to `ereg`.

// Using preg_match for regex validation
$pattern = "/^[0-9]+$/";
$string = "12345";

if (preg_match($pattern, $string)) {
    echo "Valid input";
} else {
    echo "Invalid input";
}