Skip to content

Instantly share code, notes, and snippets.

@jeremypage
Last active February 9, 2019 08:09
Show Gist options
  • Save jeremypage/1367702fb21e5aebd1797127a31721f7 to your computer and use it in GitHub Desktop.
Save jeremypage/1367702fb21e5aebd1797127a31721f7 to your computer and use it in GitHub Desktop.
jQuery Validate: Custom unobtrusive date validator (fixes Chrome date validation bug)
// Handle Chrome date validation 'bug'
jQuery.validator.addMethod('date', function (value, element) {
jQuery.culture = Globalize.culture("en-GB");
var date = Globalize.parseDate(value, "dd/MM/yyyy", "en-GB");
return this.optional(element) || !/Invalid|NaN/.test(new Date(date).toString());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment