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 8999475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:11:07+00:00 2026-06-16T00:11:07+00:00

I want my users to be able to enter a time form. If more

  • 0

I want my users to be able to enter a time form.
If more info necessary, users use this to express how much time is needed to complete a task, and it will be saved in a database if filled.

here is what I have:

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

It matches an empty form or 01:30 and 01:30:00 formatted times. I really won’t need the seconds as every task takes a minute at least, but I tried removing it and it just crashed my code and removed support for empty string.. I really don’t understand regex at all.

What I’d like, is for it to also match simple minutes and simple hours, like for instance 3:30, 3:00, 5. Is this possible? It would greatly improve the user experience and limit waste typing. But I’d like to keep the zero optional in case some users find it natural to type it.

  • 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-16T00:11:08+00:00Added an answer on June 16, 2026 at 12:11 am

    I think the following pattern does what you want:

    p="((([01]?\d)|(2[0-4])):)?([0-5]\d)?(:[0-5]\d)?"
    

    The first part:

    (([01]?\d)|(2[0-3])):)?
    

    is an optional group which deals with hours in format 00-24.

    The second part:

    ([0-5]\d)?
    

    is an optional group which deals with minutes if hours or seconds are present in your expression. The group also deals with expressions containing only minutes or only hours.

    The third part:

    (:[0-5]\d)?
    

    is an optional group dealing with seconds.

    The following samples show the pattern at work:

    In [180]: re.match(p,'14:25:30').string
    Out[180]: '14:25:30'
    
    In [182]: re.match(p,'2:34:05').string
    Out[182]: '2:34:05'
    
    In [184]: re.match(p,'02:34').string
    Out[184]: '02:34'
    
    In [186]: re.match(p,'59:59').string
    Out[186]: '59:59'
    
    In [188]: re.match(p,'59').string
    Out[188]: '59'
    
    In [189]: re.match(p,'').string
    Out[189]: ''
    

    As every group is optional the pattern matches also the empty string. I’ve tested it with Python but I think it will work with other languages too with minimal changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want users to be able to enter data from a web server and/or
I don't want users to have to enter their passwords each time, and I
I want to be able to enter a URL into a form, without clicking
I am working on a form widget for users to enter a time of
I want the user to be able to enter a name for a file
Alright, so I want the user to be able to enter every character from
I want users to be able to upload files via FTP to my site
In my app I want users to be able to associate a file(s) they
Similar Stack Overflow Question I want users to be able to search through my
In my Rails app I want users to be able to input video links

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.