Using filter_var() to verify date?

前端 未结 8 1310
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:33

    You received a lot of answers that indicated the RegEx would allow for an answer of 99/99/9999. That can be solved by adding a little more to the RegEx. If you know you'll never have a date outside of the years 1900-2099... you can use a RegEx like this:

    /^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$/
    

    That will validate a date of this format: dd/mm/YYYY

    Between: 01/01/1900 - 31/12/2099

    If you need more years, just add them near the end. |21|22|23|24|25 (would extend it to the year 2599.)

提交回复
热议问题