What's the best approach to get Date/Time input from the user?

后端 未结 12 1362
感情败类
感情败类 2021-02-02 15:34

This is a wheel that\'s been re-invented again and again over the years.

The Problem: The user needs to input a Date/Time

Basic considerations

12条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 16:27

    I'd suggest you also allow for users who like to type rather than click on a calendar control, so a combination of text box + popup calendar works well.

    We created a custom control with just such a combination. User can type a date in a variety of formats in the textbox, or click on a button to pop up the calendar.

    We allow all sorts of input like "today", "wed", or "+2" (for day after tomorrow) and use regular expressions for most of the validation client side. We also do server side validation of course.

    The control also has an optional textbox for time which can be enabled or hidden by a property. We felt it was easier to separate date from time. For times, we allow "9pm", "2100", "09:00" etc.

    The control caters for a min and max date, so that date of birth can have a range from say -100 years to current year, while credit card expiry might range from current year to +5 years, and so we use range validators.

提交回复
热议问题