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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:39:25+00:00 2026-05-12T07:39:25+00:00

I need a regex which restricts an hour entry from 0-24 with the fraction

  • 0

I need a regex which restricts an hour entry from 0-24 with the fraction in multiples of .25. Please keep in mind the following conditions must be met:

  • When whole part is 0-23, the fractional part can be .0, .25, .5, or .75
  • When whole part is 24, the fractional part can be .0
  • When no whole part is present, the fractional part must be .0, .25, .5, or .75
  • Empty string is not allowed

I am very confident that the following expression can be tightened up, but this is what is in place thus far:

(^(([0-9])|(1[0-9])|(2[0-3]))(\.((0*)|(250*)|(50*)|(750*)))?$)|(^24(\.0*)?$)|(^\.((0+)|(250*)|(50*)|(750*))$)

Update: The regex validation exists both on the client (javascript) and server (asp.net, c#).

  • 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-05-12T07:39:25+00:00Added an answer on May 12, 2026 at 7:39 am

    And the reason why you absolutely, positively need to do this as a regular expression is why? Converting to a number and doing a few basic checks would be far easier.

    Check if the number multiplied by 4 is a natural number <= 96, done.

    Judging by your profile you’re probably using .NET. I assume you want this as a regular expression because you’re using a it for client side validation. I would seriously consider using a CustomValidator with a client side JavaScript.

    Something along these lines for the JavaScript:

    <script type="text/javascript">
    function checkDuration(text)
    {
        var tmp = parseFloat(text) * 4;
        return tmp >= 0 && tmp <= 96 && Math.ceil(tmp) == tmp;
    }
    </script>
    

    Edit: I was slightly concerned about rounding errors when using floats, but it seems to work out okay for all possible cases.

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

Sidebar

Related Questions

I need a regex that will give me the following results from each example
I need to make regex which will capture the following: Fixed unicode text: <br>
I need a regex (JavaScript) which will extract shortforms from a string for example
I need a regex which will do the following Extract all strings which starts
I need regex which contains only 0-9 numbers and the following characters: -,+,# (but
I need a RegEx pattern which matches from where to the end of the
I need a regex which will satisfy both conditions. It should give me true
I need a regex pattern which will accommodate for the following. I get a
Hi have this URL string which I need to extract possibly using regex but
I need a regex that matches the following (the brackets indicate I want 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.