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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:50:13+00:00 2026-05-25T14:50:13+00:00

I have a text box in a form to enter time and I use

  • 0

I have a text box in a form to enter time and I use to check the validation using jquery. But now I want to check the validation of the text box using the codeigniter’s built-in validation system. Would you please kindly tell me how to validate time input using codeigniter’s built-in validation system?

Here’s the code how I use to do it using jquery:

<script type="text/javascript">

$().ready(function() {

$.validator.addMethod("time", function(value, element) {  
return this.optional(element) || /^(([0-1]?[0-2])|([2][0-3])):([0-5]?[0-9])\s(a|p)m?$/i.test(value);  
}, "Enter Valid Time");

    $("#theForm").validate({
            rules: {
                    time: "required time",
            },

    });

 });

</script>

And here is the html

<input class="time" type="text" name="time1" size="15">
  • 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-25T14:50:14+00:00Added an answer on May 25, 2026 at 2:50 pm

    Something like this perhaps

    // Validation rule in controller
    $this->form_validation->set_rules('time', 'time', 'trim|min_length[3]|max_length[5]|callback_validate_time');
    

    and a callback:

    public function validate_time($str)
    {
    //Assume $str SHOULD be entered as HH:MM
    
    list($hh, $mm) = split('[:]', $str);
    
    if (!is_numeric($hh) || !is_numeric($mm))
    {
        $this->form_validation->set_message('validate_time', 'Not numeric');
        return FALSE;
    }
    else if ((int) $hh > 24 || (int) $mm > 59)
    {
        $this->form_validation->set_message('validate_time', 'Invalid time');
        return FALSE;
    }
    else if (mktime((int) $hh, (int) $mm) === FALSE)
    {
        $this->form_validation->set_message('validate_time', 'Invalid time');
        return FALSE;
    }
    
    return TRUE;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an form validation using ajax/php. Each text box is validated using
I have a form. And an text box inside it. I wrote validation for
I have a php form with two text boxes and i want to enter
using jquery I have a autocomplete text box like the combobox example on the
I have a single text box form on my home page (/). Right now
I have a form with a text box for a user to enter a
I have a C# form that has a text box that needs to constantly
I have a form that asks users to enter a start and end time
I have a text-box which allows users to enter a word. The user enters:
Greetings, I have a form where employees enter comments in a multiline textbox with

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.