Page 1 of 1

How to check time correctly?

Posted: Fri Sep 06, 2002 5:14 am
by 9902468
I'm using this function to check time:

Code: Select all

//function that checks time syntax (hh.mm), correct values etc..
                        function check_time($time){

                                $return = 0;

                                if( ereg("(ї0-9]{1,2})\.(ї0-9]{1,2})", $time) ){

                                        $time_info = explode(".", $time);

                                        if($time_info&#1111;0] < 24 && $time_info&#1111;0] >= 0 && $time_info&#1111;1] < 60 && $time_info&#1111;1] >= 0)&#123;

                                                $return = 1;
                                        &#125;else&#123;
                                                $return = 0;
                                        &#125;

                                &#125;else&#123;
                                        $return = 0;
                                &#125;

                        return $return;

                        &#125;
But it returns 1 if I input time that has many zeros like 0002.22. I don't want that to be ok. (Don't ask why ;) ) Is there something I'm missing?

thanks

-9902468

Posted: Fri Sep 06, 2002 9:47 am
by phice
http://www.time.gov usually has the right time.. ;)

Posted: Fri Sep 06, 2002 11:00 am
by Takuma
OK if your time is in this format

Code: Select all

hh:mm
Use this reg expression

Code: Select all

&lt;?php
ereg("^&#1111;0-9]{2}:&#1111;0-9]{2}");
?&gt;