Using filter_var() to verify date?

前端 未结 8 1233
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:35

    A simple and convenient way to verify the date in PHP is a strtotime function. You can validate the date with only one line:

    strtotime("bad 01/02/2012 bad"); //false
    strtotime("01/02/2012"); //1325455200 unix timestamp
    
    0 讨论(0)
  • 2021-01-12 02:35

    Try setting the start and end for your regex like this:

    $myregex = "/^\d{2}\/\d{2}\/\d{4}$/";
    
    0 讨论(0)
提交回复
热议问题