I have an ASP.NET MVC project, and I'm using jquery.validate.unobtrusive to perform client side validation of values. However, I'm having issues validating dates. The system needs to support multiple cultures, however the majority of current users are from the UK, so use the UK date format.
By default, this fails validation even when a valid date is entered, stating the Date field must be a valid date.
I found the following code online to change the date formatting:
$.culture = Globalize.culture("en-GB");
$.validator.methods.date = function (value, element) {
//This is not ideal but Chrome passes dates through in ISO1901 format regardless of locale
//and despite displaying in the specified format.
return this.optional(element)
|| Globalize.parseDate(value, "@ViewBag.DateFormat", "en-GB")
|| Globalize.parseDate(value, "yyyy-mm-dd");
};
However this no longer seems to be valid - I get a "Globalize.culture is not a function" error. However, If I remove that line, I get no validation at all on any field.
It seems that you need to download jquery.globalize to use that code, however this has now been pulled from Github and merged into newer versions of JQuery (which I cannot use due to conflicts with other libraries).
Using the new Globalize also does not appear to work.
Is there an easier way of performing Date validation that will work with any culture? Or is there a link somewhere to an older copy of Globalize that will work as suggested?