【问题标题】:HTML5 Input pattern for date日期的 HTML5 输入模式
【发布时间】:2018-05-09 05:20:42
【问题描述】:

我的尝试:

  Year <select ng-options="x for x in ['2018']" required>      </select> 
  Month: <input  pattern="[0-1][0-9]" maxlength="2"   required></input> 
  Day: <input  pattern="[0-3][0-9]" maxlength="2"   required></input>  

为年、月、日创建输入框,具有以下输入验证。您对接受以下参数的 HTML5 输入表单模式有什么建议吗?

  • 年份 [2018]
  • 月 [01-12]
  • 月 [1,3,5,7,8,10,12] 的第 [01-31] 天
  • 月 [4,6,9,11] 的第 [01-30] 天
  • 月 [2] 的第 [01-28] 天

是否可以在输入模式中添加以下条件。

  • 如果选择第1个月,日期输入框允许1-31,
  • 如果选择第2个月,日期输入框允许1-28

【问题讨论】:

  • 你不能使用 javascript 日历/日期选择器吗?
  • 我可以在 angularJS 中使用 JS 日期选择器吗?输入框是用angular控制器写的

标签: regex html forms design-patterns input


【解决方案1】:

以下是您要求的日期的一些模式。但是,我认为仅使用正则表达式无法解决此问题,因此您可能需要 HTML/Js 解决方案。

(1\d{3}|2\d{3}) //Matches all the years between 1000 and 2999
(0[1-9]|1[0-2]) //Matches all numbers from 01 to 12
([0-2]\d|3[0-1])//Matches days from 01 to 31
([0-2]\d|30)    //Matches days from 01 to 30
([0-1]\d|2[0-8])//Matches days from 01 to 28

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 2013-03-06
    • 2015-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多