Regular Expression to validate a timestamp

后端 未结 13 554
名媛妹妹
名媛妹妹 2021-01-01 01:19

I need a regular expression to validate a timestamp of the format, using Javascript:

YYYY/MM/DD HH:MI:SS

I trie

13条回答
  •  礼貌的吻别
    2021-01-01 01:58

    If you just want to validate the syntax, here is the POSIX regex:

    [0-9]{1,4}/[0-9]{1,2}/[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}
    

    But if you want to check the semantics, I would process the string using your language of choice, there are too many cases you cannot cover with regular expressions (like leap years/seconds, daylight savings, etc)

提交回复
热议问题