jQuery Validate 中的日期格式 dd/mm/yyyy 的客户端验证失败 [英] Clientside validation fails for date format dd/mm/yyyy in jQuery Validate

查看:12
本文介绍了jQuery Validate 中的日期格式 dd/mm/yyyy 的客户端验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MVC 5 应用程序中使用 jQuery Validate 插件进行客户端验证.对于日期字段,使用 dd/mm/yyyy 格式时,cilentside 验证失败.有没有办法在 jQuery 验证中更改日期格式?

I am using jQuery Validate plugin for clientside validation in an MVC 5 application. For the date fields cilentside validations fails when using dd/mm/yyyy format. Is there a way to change the date format in jQuery Validation?

推荐答案

添加到 Darin 的答案中.如果您碰巧已经在使用 JQuery UI 中的 datepicker 插件,那么您可以使用该日期解析器而不是创建自己的:

Adding to Darin's answer. If you happen to already be using the datepicker plugin from JQuery UI then you can use that date parser instead of creating your own:

$.validator.methods.date = function (value, element) {
    return this.optional(element) ||  $.datepicker.parseDate('dd/mm/yy', value);
}

这篇关于jQuery Validate 中的日期格式 dd/mm/yyyy 的客户端验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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