Does anyone know of a reg expression for uk date format

后端 未结 7 922
青春惊慌失措
青春惊慌失措 2021-01-18 21:39

Hi does any one know a reg ex for a uk date format e.g. dd/mm/yyyy.

The dd or mm can be 1 character e.g. 1/1/2010 but the year must always be 4 characters.

T

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 22:22

    I ran into the similar requirements. Here is the complete regular expression along with Leap Year validation. Format: dd/MM/yyyy

    (3[01]|[12]\d|0[1-9])/(0[13578]|10|12)/((?!0000)\d{4})|(30|[12]\d|0[1-9])/(0[469]|11)/((?!0000)\d{4})|(2[0-8]|[01]\d|0[1-9])/(02)/((?!0000)\d{4})| 29/(02)/(1600|2000|2400|2800|00)|29/(02)/(\d\d)(0[48]|[2468][048]|[13579][26])

    It can be easily modified to US format or other EU formats.

    edited:

    (3[01]|[12]\d|0[1-9])/(0[13578]|10|12)/((?!0000)\d{4})|(30|[12]\d|0[1-9])/(0[469]|11)/((?!0000)\d{4})|(2[0-8]|[01]\d|0[1-9])/(02)/((?!0000)\d{4})|29/(02)/(1600|2000|2400|2800|00)|29/(02)/(\d\d)(0[48]|[2468][048]|[13579][26])

提交回复
热议问题