A problem i always have is making sure people enter dates into forms int he correct format.
Say i wanted all dates to be ntered like 05-08-2004 i have a number of options
Option 1
Let the user enter anything they want, then use REGEX to check it. If it is wrong, spit out an error.
Good thing about this is that it is less time consuming for the user to fill in the dates as there are going to be quite a few date fields on the forms i am using
Option 2
Use select boxes in the form, so the user can only select options that are correct, not allowing them to enter incorect data. Making the user select the day number, the month number and the year from a drop down can be time consuming and laborious when there are a few date fields to be completed.
What other options could there be? What method would you go for?
Mark
Methods for making sure date is entered in correct format
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
1) if using a database you cast try to cast the date using a select and see if a result is returned.
2) Use the php strtotime function
http://www.php.net/manual/en/function.strtotime.php
Example of use ripped from the page...
Advantage user can put in additional information such as
2) Use the php strtotime function
http://www.php.net/manual/en/function.strtotime.php
Example of use ripped from the page...
Code: Select all
<?php
$str = 'Not Good';
if (($timestamp = strtotime($str)) === -1) {
echo "The string ($str) is bogus";
} else {
echo "$str == " . date('l dS of F Y h:i:s A', $timestamp);
}
?>Code: Select all
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>I'd use the pulldown menus. It requires on less page load. Alternatively, you could pop up a calendar and let them just click . I use http://javascript.internet.com/calendar ... icker.html often
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.