client side date validation not working in non-US culture RRS feed

  • Question

  • User-1788333643 posted

    I have an ASP.net MVC 5 website that has a date picker on the form.  The culture on the website is set to Polish (pl-PL) which uses a European date format DD.MM.YYYY.  I am using datepicker-pl-PL.js for the date picker on my form.  The markup on the form does include the jQuery validation scripts.  My problem is when the form is submitted the client side validation says "The field MIX DATE is not in the correct format" but it is in the DD.MM.YYYY format upon submission.  I don't have any data annotations set for that field either, I checked that.  I've done some research on the web but nothing has worked.  How do I get client side validation to work for this date format?

    Friday, September 20, 2019 5:53 PM

All replies

  • User303363814 posted

    I would assume that the picker gives you a value of type DateTime.  You should pass that DateTime value to the back end, not the string that the user entered.

    Can you show some of your code? Maybe we can help more.

    Wednesday, September 25, 2019 10:43 PM
  • User-1788333643 posted

    If I pass date time of "dd.MM.yyyy hh:mm:ss" from the datepicker it doesn't work either, I get the same error message on the CLIENT side.  So I guess the question is how do I get Jquery client side validation to recognize a date based on the culture.  It's as if it only recognizes US dates as valid.  I've researched a lot on the web over the last month and I have not found a solution.  I looked at using Globalize but I have no idea how to implement it in my ASP.net MVC 5 application; I tried following the example but it didn't work at all, I got lots of JavaScript errors saying Globalize is not recognized.  I'm stuck.

    I currently have this in my web.config which defines my culture (normally this is set to "auto" and I let the browser language dictate the culture but when debugging I'm forcing it to Polish):

     <globalization fileEncoding="utf-8" requestEncoding="utf-8" culture="pl-PL" uiCulture="pl-PL" enableClientBasedCulture="true" />

    My bundleconfig.cs does include the datepicker-pl-PL.js file but the date picker is not the problem, the date picker is showing the date in the European format as expected so that is working just fine.  The issue is when I click the SAVE button to submit the form the CLIENT side validation is complaining my date is not in the correct format.

    Friday, October 25, 2019 3:00 PM