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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:24:04+00:00 2026-06-01T21:24:04+00:00

I have an input field where the user enters a time in format mm:hh.

  • 0

I have an input field where the user enters a time in format mm:hh. The format is specified inside the field (default value 09:00) but I still want to perform a client-side check to see if the format is correct.

Since the existing client-side validation is in jQuery, I’d like to keep this in jQuery as well.

I’m mainly a PHP programmer so I need some help writing this one in an optimal manner.

I know I can check each individual character (first two = digits, third = ‘:’, last two = digits) but is there a way to do it more elegantly, while also checking the hour count is not larger than 23 and the minute count isn’t larger than 59?

In PHP I would use regular expressions, I assume there’s something similar for jQuery?

Something like this makes sense to me:

([01]?[0-9]|2[0-3]):[0-5][0-9]

But I’m not too familiar with jQuery syntax so I’m not sure what to do with 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-01T21:24:05+00:00Added an answer on June 1, 2026 at 9:24 pm

    you can use regex in JavaScript too:

    http://www.w3schools.com/jsref/jsref_obj_string.asp

    use
    .search() – http://www.w3schools.com/jsref/jsref_search.asp

    or .match() – http://www.w3schools.com/jsref/jsref_match.asp

    or .replace() – http://www.w3schools.com/jsref/jsref_replace.asp

    EDIT:

    <script>
        var regexp = /([01][0-9]|[02][0-3]):[0-5][0-9]/;
        var correct = ($('input').val().search(regexp) >= 0) ? true : false;
    </script>
    

    EDIT2:

    here the documentation of regexpobject in javascript:

    http://www.w3schools.com/jsref/jsref_obj_regexp.asp

    <script>
        var regexp = /([01][0-9]|[02][0-3]):[0-5][0-9]/;
        var correct = regexp.test($('input').val());
    </script>
    

    EDIT3:

    fixed the regexp

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

Sidebar

Related Questions

I don't want to have a formal form field but save every user input
I have an input edit field where the user can enter data. I want
I have a form with an input field where a user enters a unique
I have an input field on my page where the user will type in
TABLE bcompany companyID | cName | ... I have the input field, where user
I have an input field that is by default set to type=text so that
I have an input field which has a placeholder text. I want one word
I have an input field and I want to limit it to alphanumerical (A-Z,
So I have a simple Edit-text with number input. User enters his phone number
I have a GMT field in which the user enter a time to be

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.