我的尝试:
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]
- 日 [01-31] 月份 [1,3,5,7,8,10,12]
- 天 [01-30] 为 月 [4,6,9,11]
- 天 [01-28] 为 月 [2]
是否可以将以下条件添加到输入模式中。
- 如果选择第 1 个月,则当天的输入框允许 1-31,
- 如果选择第 2 个月,则当天的输入框允许 1-28
以下是您请求日期的一些模式。但是,我认为仅使用正则表达式无法解决这种情况,因此您可能需要一个 HTML/Js 解决方案。
(1d{3}|2d{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