简体   繁体   English

jQuery datepicker验证失败

[英]jQuery datepicker validation fail

Have a form which includes a jQuery Datepicker. 有一个包含jQuery Datepicker的表单。 The date format is in the UK format (day/month/year) however the datepicker keeps failing the validation if the first number, which should be the day is greater than 12 suggesting it's trying to validate against the US format and therefore seeing the day as a month. 日期格式采用英国格式(天/月/年),但是如果第一个数字(应该是日)大于12,则日期选择器会继续使验证失败,这表明它正在尝试针对美国格式进行验证,因此看到了这一天一个月。 In chrome this stops the form being submitted. 在chrome中,这将停止提交表单。 Code below is the js used to initialise the datepicker: 以下代码是用于初始化日期选择器的js:

    $(".datepicker").datepicker({
        showOn: "button",
        buttonImage: "/Images/calendar.gif",
        buttonImageOnly: true,
        dateFormat: "dd/mm/yy"
    });

An example date that should pass validation but doesn't would be 31/07/2015 应通过验证但未通过验证的日期为2015年7月31日

I'm equally happy to remove the validation if it can not be made to validate correctly. 如果无法正确验证,我也很乐意删除验证。

确保没有其他客户端/服务器端验证生效,我怀疑JQuery Datepicker dateFormat是一个红色鲱鱼。

I do not believe your issue is in fact with the format of the date. 我认为您的问题实际上与日期格式无关。

Take a look at the link here: http://api.jqueryui.com/datepicker/#utility-formatDate 在这里查看链接: http : //api.jqueryui.com/datepicker/#utility-formatDate

If you notice, it says you can use any combination of the formats. 如果您注意到,它表示您可以使用格式的任意组合。 I believe this to be a validation issue elsewhere and not the initialization of the datepicker. 我认为这是其他地方的验证问题,而不是datepicker的初始化。 If the datepicker were at fault, it would not input the date in the proper format, even before validation. 如果日期选择器有问题,则即使在验证之前也不会以正确的格式输入日期。

Check your date field that you applied this to. 检查您将其应用到的日期字段。 You may need to format the date explicitly for that input field so that it will accept your datepicker's format 您可能需要为该input字段明确格式化日期,以便它接受您的日期选择器格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM