Our system has a text field attached calendar widget.
When a user clicks the text field, then calendar pops up,
and it fills the text field with dd/mm/yyyy format as user selects a date on the calendar. something like 30/10/2008
But there is also chances that user might try to enter different date format by deleting the date and entering a date manually, something like 10/30/2008, or Oct 30, 2008 which we don't want.
And there is a submit button, so when user clicks the submit button, I need to give them error message for wrong date format.
How can I validate(force) the text field to have only dd/mm/yyyy date format?
Thanks in advance,
You have a few techniques at your disposal.
1) On the server, use PHP to check the values submitted by the user. Display an error if their values are wrong, and force them to enter it again. This is the most idiot-proof way.
4) Fancy-pants degradable AJAX form validation (example).
In any case, I'd recommend having three separate labeled fields (day, month and year) to prevent mm/dd/yyyy vs. dd/mm/yyyy misunderstandings.
I agree with last post.
use checkdate function in case they enter erronious data like 30/2/2008 too.
Inevitably you will find out its far easier to let users pick from a drop-list of values, use checkdate in the first instance on the client to filter out hacks.
This topic is now closed. New replies are no longer allowed.