Forum Moderators: coopster
function valid_date($var){
if(empty($var)){
return false;
}
$year = substr($var, 0, 4); //year
$first_dash = substr($var,4,1); //first dash
$month = substr($var,5,2); //month
$second_dash = substr($var, 7,1); //2nd dash
$day = substr($var, 8, 2); //day
if(!is_numeric($year) ¦¦ strcasecmp($first_dash, "-")!=0 ¦¦ strcasecmp($second_dash, "-")!=0 ¦¦ empty($month) ¦¦ empty($day)){
return false;
}
$first_digit = substr($month, -2,1);
$second_digit = substr($month, -1,1);
//echo "\$first_digit: $first_digit<br>";
//echo "\$second_digit: $second_digit<br>";
//not numbers
if(!is_numeric($first_digit) ¦¦!is_numeric($second_digit)){
return false;
}
//months cannot go above 12
if($first_digit > 1){
return false;
}
if($first_digit == 1 && $second_digit > 2){
return false;
}
(int)$first_digit = substr($day, -2,1);
(int)$second_digit = substr($day, -1, 1);
if(!is_numeric($first_digit) ¦¦!is_numeric($second_digit)){
return false;
}
if($first_digit>3){
return false;
}
if($first_digit ==3 && $second_digit > 1){
return false;
}
return true;
}