Html 输入类型日期最小值和最大值根据 yyyy-mm-dd 而不是 dd-mm-yyyy 进行验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17443034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
input type date min and max values validate against yyyy-mm-dd instead of dd-mm-yyyy
提问by Casper Thule Hansen
I am using the date input type in HTML5. It is displaying the correctly in the format dd-MM-yyyy. However the min and max values does not validate correctly, because it validates against the format yyyy-MM-dd. I have not been able to change the format the min and max values validates, any ideas?
我在 HTML5 中使用日期输入类型。它以 dd-MM-yyyy 格式正确显示。但是,最小值和最大值无法正确验证,因为它根据格式 yyyy-MM-dd 进行验证。我无法更改最小值和最大值验证的格式,有什么想法吗?
<input type="date" name="DateName" id="DateID" min="2000-01-01" max="2100-12-31"/>
回答by Jonathan Naguin
The attributes value
, min
and max
have the same format for dates. They follow the RFC 3339where the full data syntax is as:
属性value
,min
并max
有日期相同的格式。它们遵循RFC 3339,其中完整的数据语法如下:
full-date = date-fullyear "-" date-month "-" date-mday
date-fullyear = 4DIGIT
date-month = 2DIGIT (01-12)
date-mday = 2DIGIT (01-28, 01-29, 01-30, 01-31)
So even if the browser displays you the date in format dd-mm-yyyy
internally it's using this syntax.
因此,即使浏览器在dd-mm-yyyy
内部以格式显示日期,它也会使用此语法。
Anyway, this HTML5 input type is only supported in Safari, Chrome and Opera.
无论如何,这种 HTML5 输入类型仅在 Safari、Chrome 和 Opera 中受支持。
You can try this Fiddlewith invalid dates as 12/12/2014, when you submit the form an error message is displayed.
您可以尝试使用无效日期作为 12/12/2014 的这个小提琴,当您提交表单时,会显示一条错误消息。