简体   繁体   中英

How do I let my users insert a date in a specific format?

In an internal CMS/Order System we have a 'deadline' input field. Currently this is just a plain text and stored as such in the database (varchar). I want to change this since I can't work with this data in any way. The input should be that of a date (day-month-year).

What is the best way to do this? The solutions I came up with:

  1. Use HTML5's <input type="date" /> . This could work since we only use modern browsers internally.
  2. jQuery datepicker. I havent really worked with jQuery before but I think this is a solid soluton.
  3. Let users do whatever they want and use strtotime() ?

Any thoughts on how to handle this?

My simple suggestion is,

You can give a label text like Note: Date format should be "dd-mm-yyyy" below the text box.

Then you can validate the input format in Javascript & PHP. There are so many validation scripts available.

(or)

Use Datepicker for user friendly.

I think you can use jquery date picker because its more userfriendly and keeping the datepicker readonly there is no need of further validation for date.Also you can change the desired format of date.

For reference check these links

http://jqueryui.com/datepicker/

http://keith-wood.name/datepick.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM