Hi
I'm trying to write an expression that will test a date format so that it will validate a date string
basically i need to check that a date is in the yyyy-mm-dd format and that it isn't 0000-00-00
so far I've got this
"([0-9]{4})-([0-9]{2})-([0-9]{2})"
but it's wrong because I'm getting the error
and also it will accept 0000-00-00 as ok - what i need is for it to say that in each part [0-9] is acceptable but it must have at least 1 instance of [1-9]
here's my code so far :
function testDate($dt){
if(preg_match("([0-9]{4})-([0-9]{2})-([0-9]{2})",$dt,$regs)){
echo $dt." is ok<br />";
}else{
echo $dt." is not ok<br />";
}
}
$str[1] = "2010-01-29";
$str[2] = "0000-00-00";
$str[3] = "0";
$str[4] = "";
$str[5] = "5876586868";
foreach($str as $v){
testDate($v);
}
how can I make this work ?
I was tempted to just explode() the date string using "-" as a separator and then testing if the first four characters match "2009" or "2010" or "2010" etc but i would really like to understand how to do this with an expression
thanks