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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:45:34+00:00 2026-06-01T00:45:34+00:00

Looking for the correct preg_match (or other solution) to validate a string to go

  • 0

Looking for the correct preg_match (or other solution) to validate a string to go in mysql time datatype.
The format is xxx:xx:xx and between ranges ‘-838:59:59’ to ‘838:59:59’

Also in mind that “7:53:48”, “23:59”, “145:19:59”, and “-16:24:33” are all valid inputs but “930:00:00″, 128:61:61” and “63:59” are all invalid.

I’ve got this far from a normal time preg_match

preg_match("/([0-9]):([0-5][0-9]):([0-5][0-9])$/", $time)

But this only validates the minutes and seconds properly. Any ideas !?

Also note that I understand that time mysql datatype also accepts values without the colons, but that’s been handled separately already 😉

EDIT

I’m really sorry guys, missunderstood mysql doc. 70:59 is actually valid input, it will be translated to 70:59:00

  • 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-01T00:45:35+00:00Added an answer on June 1, 2026 at 12:45 am
    (?<![0-9:])-?([0-9]|[0-9][0-9]|[0-7][0-9][0-9]|8[0-2][0-9]|83[0-8]):([0-5][0-9])(?::([0-5][0-9]))?(?![0-9:])
    

    Explanation:

    (?<!                  # look-behind: makes sure we are at the start of a time
      [0-9:]              #   ...not preceded by a digit or a colon
    )                     # end look-behind
    -?                    # a minus, optional
    (                     # group 1 (hours)
       [0-9]              #   single-digit 0-9
       |                  #   or
       [0-9][0-9]         #   double-digit 00-99
       |                  #   or
       [1-7][0-9][0-9]    #   triple-digit 100-799
       |                  #   or
       8[0-2][0-9]        #   triple-digit 800-829
       |                  #   or
       83[0-8]            #   triple-digit 830-838
    )                     # end group 1
    :                     # :
    (                     # group 2 (minutes)
       [0-5][0-9]         #   00-59
    )                     # end group 2
    (?:                   # non-capturing group
      :                   #   :
      (                   #   group 3 (seconds)
        [0-5][0-9]        #     00-59
      )                   #   end group 3
    )?                    # end group, make optional
    (?!                   # look-ahead: makes sure we are at the end of a time
      [0-9:]              #   ...not followed by a digit or a colon
    )                     # end look-ahead
    

    This actually matches time strings in a larger text, instead of just validating them.

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

Sidebar

Related Questions

Looking for the correct way and control to import and export of out of
I'm looking for (arguably) the correct way to return data from a XmlHttpRequest .
I am looking at code which has the correct using statements declared but yet
I am looking to the fastest and the correct way to check if a
I am looking at singletons and I was curious about the correct way to
I'm looking for the correct way of using wp_get_attachment_image(). The following code: <?php $args
I have the following Stored Procedure, Im looking for the correct syntax so I
I'm looking for the correct way to structure the query for a view in
I'm looking at this code of the correct way to do a singleton in
I'm looking for the best way to dispatch objects to the correct target object.

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.