SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    0 Post(s)
    0 Thread(s)

    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,

  2. #2
    SitePoint Addict fattyjules's Avatar
    Join Date
    Dec 2005
    0 Post(s)
    0 Thread(s)
    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.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    France, deep rural.
    17 Post(s)
    1 Thread(s)
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts