I have a simple view with two date fields with ValidationMessageFor controls added for the unobtrusive JavaScript validation.
My issue is I keep getting told my date is invalid, when it is in correct format (dd/MM/yyyy)
I have added <globalization culture="en-GB" uiCulture="en-GB"/>
to my web.config, and also included [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
on each DateTime property, yet it still won't accept UK format dates.
Is there anything obvious I am missing here?
Actually you just need to overload unobtrusive JavaScript validation method for date
jQuery(function ($) { $.validator.addMethod('date', function (value, element) { if (this.optional(element)) { return true; } var ok = true; try { $.datepicker.parseDate('dd/mm/yy', value); } catch (err) { ok = false; } return ok; }); });
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