2nd EDIT: I think most users would not find it easier to write the whole date/time as a long string. That requires them to "think more" and to format it properly, instead of just selecting from a predefined list.
EDIT: NullPointer got to it before me, but I'll post it anyway since I already wrote it :P
Personally I think (one of) the easiest ways would be to have drop down menus for the date (year, month, day), and normal text boxes for time (hour, minute, seconds), each with a width of two characters.
Now, for the validation part.
I would run them through a regex, and use check_date() to validate the date. I'm no regex expert but I think this shoud do it.
PHP Code:
// Fetch the data and store them in $year, $month, $day, $hours, $minutes, $seconds $time_pattern = "/^(([0-1]?[0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]$/"; $date_pattern = "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/";
$time_str = "$hours:$minutes:$seconds"; $date_str = "$year-$month-$day";
if (preg_match($time_pattern, $time_str) != 1) { // incorrect time format, do something } if (preg_match($date_pattern, $date_str) != 1) { // incorect date format, do something } if (!check_date($month, $day, $year)) { // invalid date, do something }
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
Last edited by lizciz; 06-16-2011 at 06:14 PM..
|