Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

asp.net mvc 4 - jQuery date validation MVC 4 .Net 4.5.1 UK date "must be a date" Error

I have an app that I have recently upgraded to .Net 4.5.1 and MVC 4. I am using the jQuery datepicker and jQuery.validation 1.11.1.

I am in the UK therefore the dates will be in the en-GB locale ("dd/mm/yyyy"). I have tried what is suggested here, here and here but to no avail.

I also have in my web.config:

<globalization uiCulture="en-GB" culture="en-GB" />

and have set the globalisation in IIS to en-GB, but every date that is input is validated as a US format date.

Can anyone help please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Changing the date validation method in jQuery.validate.js to the follwing solved the issue:

date: function (value, element) {
        $.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());
    }

Tested in Chrome, FF and IE


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...