How to write a regex for MM:DD:YYYY:HH:MM:SS

后端 未结 2 359
暖寄归人
暖寄归人 2021-01-26 03:48

How can I write a regex for MM:DD:YYYY:HH:MM:SS?

2条回答
  •  无人及你
    2021-01-26 04:02

    It depends whether you want to check are all characters divided by : numbers or you also want to check whether you will not get totaly improper data like the 32nd of December or the hour like 25:66. To have such a basic validation you should use a little more complex regexp than the one provided by @Pascal MARTIN, e.g.,

    [0-1][0-9]:[0-3][0-9]:[1-2][0-9]{3}:[0-2][0-9]:[0-5][0-9]:[0-5][0-9]
    

提交回复
热议问题