Regular expression for matching HH:MM time format

Regular expression for matching HH:MM time format

Asked on January 2, 2019 in Regex.
Add Comment


  • 2 Answer(s)

    The original regular expression has flaws: it will not match 04:00 for instance use this:

    ^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$
    
    
    Answered on January 2, 2019.
    Add Comment

    Use 24H and seconds are optional:

    ^([0-1]?[0-9]|[2][0-3]):([0-5][0-9])(:[0-5][0-9])?$
    
    

     

    Answered on January 2, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.