Need to validate MM/dd/yyyy hh:mm tt in Javascript

前端 未结 3 896
悲哀的现实
悲哀的现实 2021-01-28 13:19

I need to validate a date string in a specific format in Javascript.

The format is: MM/dd/yyyy hh:mm tt

I\'m having a really hard time trying to find either a da

3条回答
  •  忘了有多久
    2021-01-28 14:12

    Try this regular expression for the format dd/MM/yyyy hh:mm tt

    "[0-3][0-9]\/[0-1][0-9]\/[0-9]{4} [0-1][0-9]:[0-5][0-9] [paPA][Mm]" 
    

    the above expression works as the below formats

    01/12/9999 01:00 AM - matches
    12/31/9999 01:59 PM - no match
    39/19/9999 01:59 PM - matches
    39/19/9999 99:99 PM - no match (time out of range)
    12/31/9999 99:59 PM - no match (hours out of range)
    

提交回复
热议问题