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

  • Home
  • SEARCH
  • 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 8676369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:10:41+00:00 2026-06-12T20:10:41+00:00

This is my requirement for validating a string that could be between 1 and

  • 0

This is my requirement for validating a string that could be between 1 and 4 characters long (H stands for hour and M stand for minutes):

1 character = H (digit between 0-9)

2 characters = HH (first H is digit between 0-2, second is digit between 0-9, but if the first one is 2 the second one can only be 0-4)

3 characters = HMM (first H is digit between 0-9, first M is digit between 0-5, second M is digit between 0-9)

4 characters = HHMM (first H is digit between 0-2, second is digit between 0-9, but if the first one is 2 the second one can only be 0-4, first M is digit between 0-5, second M is digit between 0-9)

What makes this challenging is that I don’t know the length of the string in advance and the same number could mean different things depending on how long the string is. Any ideas about a JavaScript RegularExpression to validate this?

  • 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-12T20:10:43+00:00Added an answer on June 12, 2026 at 8:10 pm

    You can use a regular expression like this:

    ^(2[0-4]|[01]?\d)([0-5]\d)?$
    

    Breakdown:

    ^                   beginning of string
    2[0-4]              digit 2 followed by digit 0-4
    |                   or
    [01]?\d             digit 0-1, optional, followed by any digit
    ([0-5]\d)?          digit 0-5 followed by any digit, as whole optional
    $                   end of string
    

    Note: Perhaps you mean to have hours 0-23 instead of 0-24:

    ^(2[0-3]|[01]?\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 realized today that I have blindly just followed this requirement for years without
Wondering if I could get some advice and direction on this following requirement: Need
I have a string property that has a maximum length requirement because the data
This requirement is just for simplicity for developers and beautiful code. I'm building a
I just read this requirement on a job listing: Aware of the pitfalls of
This is my requirement: I have a bunch of radio box selections (types of
Requirement is this ... We have our 3 web-applications deployed in RHEL-5 server, we
For my ipad application i have requirement like this For each row in root
I am working in JTable and I have a requirement like this. Say There
This is a simple requirement: I want to add a set of strings to

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.