Regex for time in hh:mm am/pm format

后端 未结 5 1955
暖寄归人
暖寄归人 2020-11-29 10:32

I need to make strict validation of input for a school project, time in format HH:MM am/pm. So far i\'ve got this RegEx expression:

(([01]?[0-9]):([0-5][0-9         


        
5条回答
  •  盖世英雄少女心
    2020-11-29 10:59

    This regex has 3 parts, separated by the OR operator.
    Each part allows for a type of HH
    They are 0[1-9], [1-9], and 1[0-2].

    /(0[1-9]:[0-5][0-9]((\ ){0,1})((AM)|(PM)|(am)|(pm)))|([1-9]:[0-5][0-9]((\ ){0,1})((AM)|(PM)|(am)|(pm)))|(1[0-2]:[0-5][0-9]((\ ){0,1})((AM)|(PM)|(am)|(pm)))/
    

提交回复
热议问题