jQuery的日期验证MVC 4 .NET 4.5.1英国的日期和QUOT;必须是日期"错误 [英] jQuery date validation MVC 4 .Net 4.5.1 UK date "must be a date" Error

查看:241
本文介绍了jQuery的日期验证MVC 4 .NET 4.5.1英国的日期和QUOT;必须是日期"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我最近升级到.NET 4.5.1和MVC 4.我使用jQuery的日期选择器和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)。我曾尝试什么建议<一href="http://stackoverflow.com/questions/12053022/mvc-datetime-validation-uk-date-format/14081487#14081487">here, <一href="http://stackoverflow.com/questions/2427504/jquery-ui-datepicker-date-format-issue-with-initial-value">here和这里但无济于事。

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到follwing解决的问题:

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英国的日期和QUOT;必须是日期&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆