问题描述
我有一个应用程序,我最近升级到了 .Net 4.5.1 和 MVC 4.我使用的是 jQuery datepicker 和 jQuery.validation 1.11.1.
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.
我在英国,因此日期将采用 en-GB 语言环境(dd/mm/yyyy").我已经尝试了这里的建议,这里 和 此处 但无济于事.
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.
我的 web.config 中也有:
I also have in my web.config:
<globalization uiCulture="en-GB" culture="en-GB" />
并将 IIS 中的全球化设置为 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.
有人可以帮忙吗?
推荐答案
将 jQuery.validate.js 中的日期验证方法更改为以下解决方案:
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());
}
在 Chrome、FF 和 IE 中测试
Tested in Chrome, FF and IE
这篇关于jQuery 日期验证 MVC 4 .Net 4.5.1 UK 日期“必须是日期"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!