In my form I am using drop down for showing day, month, year. can you help me to validate the date. I have to validate the entered age is greater than 15. also checking leap year
A:
checkdate()
Age is not too hard too:
$validdate = (date("Y")-15).date("-m-d");
$bday = "$y-$m-$d";
if ($bday > $validdate) echo "underage!";
Col. Shrapnel
2010-05-26 05:24:43
Thanks to everybody for your valuable comments.
php learner
2010-05-26 07:01:23
A:
you have to first convert your input date in yyyy-mm-dd frormate.you can not directly put validatation. you have to convert your date into timestamp and then after you have to check validation.
$strSystemMaxDate = (date('Y') - 15).'/'.date('m/d');
if(strtotime($strDateOfBirth) > strtotime($strSystemMaxDate))
{
$arrErrors[] = _("Minimum age is 15 years.");
$blnValidated = false;
}
A:
<?php
$yy = $_POST[ "yy" ];
$mm = $_POST[ "mm" ];
$dd = $_POST[ "dd" ];
if ( checkdate( $mm, $dd, $yy ) === false )
{
die( "Invalid date" );
}
$birthDate = mktime( 0, 0, 0, $mm, $dd, $yy );
$fifteenYearsAgo = strtotime( "-15 years" );
if ( $birthDate > $fifteenYearsAgo )
{
die( "You're underage!" );
}
?>
Salman A
2010-05-26 05:51:56