Using filter_var() to verify date?

前端 未结 8 1230
Happy的楠姐
Happy的楠姐 2021-01-12 01:58

I\'m obviously not using filter_var() correctly. I need to check that the user has entered a valid date, in the form \"dd/mm/yyyy\".

This simply returns whatever I p

8条回答
  •  迷失自我
    2021-01-12 02:24

    Using regex to validate date is a bad idea .. Imagine 99/99/9999 can easily be seen as a valid date .. you should checkdate

    bool checkdate ( int $month , int $day , int $year )
    

    Simple Usage

    $date = "01/02/0000";
    $date = date_parse($date); // or date_parse_from_format("d/m/Y", $date);
    if (checkdate($date['month'], $date['day'], $date['year'])) {
        // Valid Date
    }
    

提交回复
热议问题