0

When using jQuery UI Datepicker in my asp.net mvc application, I encouter a problem with Google Chrome: If I enter a date with a day higher than 12, it does not accept it as a valid date, and the folowing error message is displayed : "The field Date fin must be a date". I think that this is because chrome thinks the dateformat is mm/dd/yyyy. I tried to overcome this issues by adding the following jquery code on my cshtml page (this solution is proposed on this post : The field date must be a date in mvc in chrome) :

 $(document).ready(function () {        
        jQuery.validator.methods.date = function (value, element) {            
            var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
            if (isChrome) {                
                var d = new Date();
                return this.optional(element) || !/Invalid|NaN/.test(new Date(d.toLocaleDateString(value)));
            } else {                
                return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
            }
        };
    });

But the browser return this error : Cannot read property 'methods' of undefined. Any ideas/suggestions to overcome this issues?

Thanks for your help.

Zakaria.d
  • 158
  • 1
  • 3
  • 16
  • 1
    Refer [this answer](https://stackoverflow.com/questions/27285458/jquery-ui-datepicker-and-mvc-view-model-type-datetime/27286969#27286969) for `jquery-ui` and [this one](https://stackoverflow.com/questions/39677035/date-of-birth-validation-keeps-showing/39682410#39682410) for a 'global' function and also an explanation of what is happening internally –  Jul 31 '17 at 10:30
  • Thanks Stephen, it works perfectly! – Zakaria.d Jul 31 '17 at 12:32

0 Answers0