php - Validate date month and year -


i have date in form mm-yyyy (e.g: 04-2000). exploded date month , year , trying check conditions on month:

  • between 1 , 12
  • formed of 2 digits)

and on year:

  • formed of 4 digits

is syntax correct?

list($name_month, $name_year) = explode('-', $name_date, 2); if(($name_month < 1 || $name_month > 12 || $name_month ) || ($name_year)) {     echo "<br><br>wrong date";     $uploadok = 0;} 

you can use datetime object , createfromformat() validate date:

$date = '04-2000';  $d = datetime::createfromformat('m-y', $date); if($d && $d->format('m-y') == $date){   echo 'valid date'; } 

eval.in


Comments