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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:32:27+00:00 2026-06-10T00:32:27+00:00

After google searching, searching this site as well as jQuery found there was no

  • 0

After google searching, searching this site as well as jQuery found there was no easy way to validate time value.

By the looks of things it suggest using addMethod and use the to regexpess the value to check against what time should look like.

However decided to look at the jquery.validate.js and how dateISO was checked, it looked lot easier way to do it, so I then copied all data relating to dateISO and called it timeISO and changed the string to validate time and used the following time sting

^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$ 

Is there some reason why one should not modify jquery.validate.js and do it the way I have? Just a little bit worried as all my searching on google and this forum it was never suggested.

  • 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-10T00:32:29+00:00Added an answer on June 10, 2026 at 12:32 am

    You can add custom methods to jQuery.validate. There’s probably one available for this but I coded this 24h time format validation as an example:

    $.validator.addMethod("time24", function(value, element) {
        if (!/^\d{2}:\d{2}:\d{2}$/.test(value)) return false;
        var parts = value.split(':');
        if (parts[0] > 23 || parts[1] > 59 || parts[2] > 59) return false;
        return true;
    }, "Invalid time format.");
    

    Fiddle

    Documentation.

    You can also sum it up in a single regular expression (source):

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

    And if you’re using HTML5, you can use the pattern attribute:

    <input type="text" pattern="([01]?[0-9]|2[0-3])(:[0-5][0-9]){2}" 
        required="required" placeholder="hh:mm:ss" />
    

    Fiddle

    Keep using the jQuery.validate method if you need compatibility with older browsers though:

    $.validator.addMethod("time24", function(value, element) {
        return /^([01]?[0-9]|2[0-3])(:[0-5][0-9]){2}$/.test(value);
    }, "Invalid time format.");
    

    Demo

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

Sidebar

Related Questions

After searching Google I found one way to call a master page function from
After doing lot of research in Google, I found this program: #include <stdio.h> int
after searching google i got a code which works but this code download all
I've been searching through the Devise RDocs, Google, on this site for answers to
I got this message when doing some javascript programming, and after some google searches,
Partials in XML builder are proving to be non-trivial. After some initial Google searching,
I've already tried Google searching for this and looking at the source for this
I have a very tricky problem and after long searching (google, stackoverflow, ...) i
Hi after searching on google i come here to ask about help. I use
Right now i am trying to create a graph in android,after searching from google

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.