3

I have an input field that is being set as a date picker. When I initialize the dateFormat option it stops constraining the input and I can enter all sorts of rubbish dates in the text box. Why does this happen? I'd like to have constrained input still work when setting a custom date format.

myTextInput.datepicker({ dateFormat: "dd-M-yy" });

If I don't set the dateFormat option then the input is constrained as expected.

John Mills
  • 10,020
  • 12
  • 74
  • 121

1 Answers1

3

It doesn't appear to be the custom date format itself that is breaking it. It appears that when your dateFormat includes a string representation that it isn't restricting.

$('#mydate').datepicker({ dateFormat: "yy-mm-dd" });

This seems to work correctly.

So basically the codes M, MM, D and DD break it.

MacAnthony
  • 4,471
  • 2
  • 23
  • 26
  • Ah ok, I get what you mean. So because the format I'm using allows dates like 12-JUL-2010, it will basically disable the constraints and allow any text. I thought it would've been smarter and only allowed the characters in JAN, FEB, MAR, etc. Any idea how to easily restrict the text entered in with jQuery? – John Mills Jul 15 '10 at 04:16
  • 1
    The documentation makes it sound like it should be smarter as well. You could make your own constraint on the field to only allow numbers and alpha characters. A solution for that is here (just ignore the preview stuff) http://stackoverflow.com/questions/1397535/block-characters-from-input-text-field-mirror-input-into-span-or-div – MacAnthony Jul 15 '10 at 04:48
  • i have a format of dd/mm/yy and it doesn't work, no string represantation xD – max4ever Dec 07 '11 at 10:06