Regex to validate date format dd/mm/yyyy

后端 未结 21 2582
挽巷
挽巷 2020-11-21 06:32

I need to validate a date string for the format dd/mm/yyyy with a regular expresssion.

This regex validates dd/mm/yyyy, but not the invalid

21条回答
  •  忘掉有多难
    2020-11-21 07:24

    For date MM/DD/YYYY you can use

    ^((((0[13578])|([13578])|(1[02]))[\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\/](([1-9])|([0-2][0-9]))))[\/]\d{4}$|^\d{4}$
    

    It verify proper days and moths.

    Remeber that you can check your regular expression at

    regex101

    which i recommend :)

    Have fun!

提交回复
热议问题