Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

[newbie] time validation
I'm working on a php front end to a mysql scheduling database. The
database is used to generate a calendar of work shifts. My code is
meant to allow staff members to enter their work shifts. The resulting
calendar already exists and works.

Part of the web form requires that staff members enter the start and
end times of their work shifts (these vary). They are stored in the
database in 24-hour time with a colon between the hours and minutes.
We use '24:00' and '00:00' to differentiate between different days in
the calendar. The times are stored in '$startt' and '$endt'.

So, a staff member might enter a $startt of 16:00 and an $endt of
24:00. Since it's my job to make sure everything is validated, I have
to check if the values are correct times (and not names or prices or
other errors).

I can't find any useful php functions that deal with clock time
without the corresponding 'date' information. So, my first question is
"Did I miss a function that would do this?"

Assuming I didn't miss a useful existing function, I then would like
some help with constructing my own.

The most minimal check seems to be something that would determine if
there's two numbers (between 00 and 24) to the left of a colon, and
two other numbers (between 00 and 59) to the right of a colon.

So, in pseudo-code, something like this:

list($hrs, $mins) = explode(":", $startt);
echo $hrs;
echo $mins;

 and(gte(00),lte(24)),$hrs),and(gte(00),l
te(59),$mins))

Here is where I start to get really stuck. I'm used to list
manipulation using a language similar to LISP (although it's not
lisp), and php has been giving me quite a bit of mental trouble.

Gwen

Report this thread to moderator Post Follow-up to this message
Old Post
Gwen Morse
11-12-04 08:56 PM


Re: [newbie] time validation

On 12 Nov 2004 07:29:50 -0800, gwen.morse@gmail.com (Gwen Morse)
wrote:

>Part of the web form requires that staff members enter the start and
>end times of their work shifts (these vary). They are stored in the
>database in 24-hour time with a colon between the hours and minutes.
>We use '24:00' and '00:00' to differentiate between different days in
>the calendar. The times are stored in '$startt' and '$endt'.
>
>So, a staff member might enter a $startt of 16:00 and an $endt of
>24:00. Since it's my job to make sure everything is validated, I have
>to check if the values are correct times (and not names or prices or
>other errors).

I got this working once I figured out that regexp matching was
functional within php.

//Check if the startt and endt are valid times:

function check_time($str)
{
//returns 1 if valid time, 0 if not
if (ereg("([0-1][0-9]|[2][0-4])(:[0-5][0-9])", $str))
return 1;
else
return 0;
}

if (check_time($HTTP_POST_VARS[startt]) == 0) {
echo "<br>The start time you entered is not valid. The
format is HH:MM";
}
elseif (check_time($HTTP_POST_VARS[endt]) == 0) {
echo "<br>The end time you entered is not valid. The
format is HH:MM";
}
else {
// if "everything" is correct, here is the submit sequence.

Gwen



Report this thread to moderator Post Follow-up to this message
Old Post
Gwen Morse
11-15-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:32 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.