Regular expression to validate valid time

后端 未结 8 1672
余生分开走
余生分开走 2020-12-03 14:24

Can someone help me build a regular expression to validate time?

Valid values would be from 0:00 to 23:59.

When the time is less than 10:00 it should also su

8条回答
  •  萌比男神i
    2020-12-03 14:46

    If you want to allow military and standard with the use of AM and PM (optional and insensitive), then you may want to give this a try.

    ^(?:(?:0?[1-9]|1[0-2]):[0-5][0-9]\s?(?:[AP][Mm]?|[ap][m]?)?|(?:00?|1[3-9]|2[0-3]):[0-5][0-9])$ 
    

提交回复
热议问题