I'm wondering if anyone can suggest a plugin or solution that would allow me to use the jQuery datepicker plugin with multiple input date formats at the same time. This would allow the user to enter the date in any of the specified formats. I.e.:
3 31 10
3/31/2010
3-31-10
I don't really care if the value gets mangled to one of the specific formats after the user tabs out. A good input masking plugin might work for my purpose too, however, this popular one seems to expect a fixed cardinality for each of the fields, which won't work because I want the user to be able to enter 3 or 03 for the month of March, for example.
It's been a while since this question was active, but if anyone is interested in solving the problem using the simpler jQueryUI datepicker, it can be accomplished by tweaking its parseDate method:
$.datepicker.inputFormats = ["dd-mm-yy", "dd/mm/yy", "dd mm yy"];//list formats to be accepted here
$.datepicker.originalParseDate = $.datepicker.parseDate;
$.datepicker.parseDate = function (format, value, settings) {
var date;
function testParse(format, value, settings) {
if ( ! date ) {
try {
date = $.datepicker.originalParseDate(format, value, settings);
} catch (Error) {
}
}
}
testParse(format, value, settings);
for(var n = 0, stop = $.datepicker.inputFormats ? $.datepicker.inputFormats.length : 0; n < stop; n++){
testParse($.datepicker.inputFormats[n], value, settings);
};
return date;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With