What if the delimeter can be either / or -
Then you say:
if (eregi('[0-9][-\/][0-9][-\/][0-9]', ...
In just the same way as you're using [] to match a range of characters between 0-9, you can also match a group of characters for the delimiter.
But you can do even better than this:
function validate_date( $date )
{
if (ereg('([0-9]{4})-\/-\/', $date, $val))
{
if ($val[1] >= $min_year && $val[1] <= $max_year)
{
return // bad year
}
else
{
return checkdate ($val[2], val[1], $val[3] );
}
}
else
{
return false;
}
(1) Putting parens around the various parts of the regex causes them to be copied into the array $var, saving a separate call to split() or explode().
(2) Using {n,n} for each component specifies the length that must match. You might want to vary the number of digits required for the year, if you expect to be entering dates before 1000 AD.
(3) The built-in function checkdate() does the rest of the heavy lifting.