<?
//validate the days in the month making the leading 0
//optional
$d = "([0-2]*[1-9]|3[0-1])";
//validate the month it can be zero padded, but doesn't
//have to be.
$m = "(([0]*[1-9])|(1[0-2]))";
//validate the year. It can be a four digit year that sarts
//with 19 or 20 followed by two digits or it can be a two
//digit year which is simply two digits. Though I personall
//recommend forcing a four digit year by using the
//following coomented code instead
//$y = "(19|20)[0-9]{2}";
$y = "(((19|20)[0-9]{2})|([0-9]{2}))";
//this defines all the legal seperators
$s = "[-:,./[:space:]]";
//now we just string those all together into the ereg
ereg("^" . $d . $s . $m . $s . $y . "$",$var);
?>
Splitting complex regexes up like this makes it easier to validate them and spot errors. Because you can test each portion individually. So you can make sure the days regex works without worring about the other portions of the regex. Though I don't recommend using this alone as it does not validate that their days is valid for the specific month you'll need an if statment for that.