Search code examples
jqueryjquery-uijquery-ui-datepicker

jQuery UI datepicker: Can you format a date and allow multiple seperator characters?


I prefer my datepicker to be formatted with this option

{dateFormat: 'mm-dd-yy'}

Ex: 06-16-2010

But, I would like to allow people to enter in a slash as a seperator instead of a dash if they choose.

Is there a way to setup the datepicker so that it defaults to mm-dd-yy but wouldn't prevent someone from entering mm/dd/yy?

I do know I can set {constrainInput:false} although then people can enter letters :(

Thanks for any help.


Solution

  • the datepicker has the altField & altFormat option so you can show one format but send the other, but thats not what you want.

    i suggest that you use datejs (http://www.datejs.com/) to parse the user input and update a hidden textbox which is linked to your datepicker.