Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8205893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:27:01+00:00 2026-06-07T08:27:01+00:00

I have a stopwatch variable that can get value in the following format: HH:MM:SS

  • 0

I have a stopwatch variable that can get value in the following format:
HH:MM:SS most of the time. 'HH' can go past 24 hours – basically any valid number.

I am not that good with this regex thingy, but was able to write something that is good for most part but fails to validate if the hour is single digit. Ex. below regex pass the time 1:10:09, though it is invalid. valid hour part should be 01.

//var stopWatchTime = '02:10:09'; //Valid
//var stopWatchTime = '00:10:09'; //Valid
//var stopWatchTime = '1234:10:09'; //Valid
//var stopWatchTime = ':10:09'; //Invalid
//var stopWatchTime = 'ax:10:09'; //Invalid
var stopWatchTime = '1:10:09'; //Invalid, should be 01:10:09. 

if(!stopWatchTime .match(/^\d+:\d{2}:\d{2}$/)){
    alert('invalid time- ' + stopWatchTime);
}
else{
    alert('valid time - ' + stopWatchTime);
}

What should I change in the regex to say it should check for any number but should have 2 digits or more in hour part?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:27:03+00:00Added an answer on June 7, 2026 at 8:27 am
    /^\d{2,}:\d{2}:\d{2}$/
    

    Change the + to a {2,} to allow it to have two or more characters

    If you want to see the things that matches and doesn’t match you can play with it here http://regexr.com?31fu4

    EDIT:
    Also if you only want to match up to 59 in the hours/minutes part use

    ^\d{2,}:(?:[0-5]\d):(?:[0-5]\d)$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some working code that I altered but I can't seem to get
In using Stopwatch.GetTimestamp() we find that if you record the return value and then
I have a very simple StopWatch application in Silverlight. I have the following private
I have absolute values of time (as in stopwatch not date/time) in various cells
I have some C# performance tests, basically running two different methods and checking that
I have the this code: var options = GetOptions(From, Value, SelectedValue); var stopWatch =
I'm developing something like a stopwatch, so I have to turn off that below
I have a problem with time measuring that's really bothering me. I am executing
I have the following code for a stopwatch function. I have 2 UIButtons. One
I have two class, one is an activity that can handle Chronometer, another is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.