How can I force user to enter dd/mm/yyyy format when I validate?

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.

  2. Use javascript to enforce a mask on input fields (example). If you do this, you should still use technique 1 as well, because some users won’t have javascript.

  3. Use javascript to check the field when the user hits the submit button (example). Again, should be used in conjunction with technique 1.

  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 [fphp]checkdate[/fphp] 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.