用于格式化输入框的HTML5模式取日期mm / dd / yyyy? [英] HTML5 pattern for formatting input box to take date mm/dd/yyyy?
本文介绍了用于格式化输入框的HTML5模式取日期mm / dd / yyyy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了jQuery datepicker,如果用户输入日期而不是从jQuery datepicker获取日期,我想用HTML5模式限制我的输入字段。
I used jQuery datepicker and I want to restrict my input field with a HTML5 pattern if a user, instead of getting the date from jQuery datepicker, types the date.
如何使用HTML5模式限制用户,以便他们只需键入 mm / dd / yyyy $格式的日期c $ c>?
How can I restrict my users with a HTML5 pattern so that they can just type the date in the form mm/dd/yyyy
?
推荐答案
最简单的方法是使用只读属性来阻止用户直接输入:
Easiest way is use read only attribute to prevent direct user input:
<input class="datepicker" type="text" name="date" value="" readonly />
或者您可以使用基于模式属性的HTML5验证。
日期输入模式(dd / mm / yyyy或mm / dd / yyyy):
Or you could use HTML5 validation based on pattern attribute. Date input pattern (dd/mm/yyyy or mm/dd/yyyy):
<input type="text" pattern="\d{1,2}/\d{1,2}/\d{4}" class="datepicker" name="date" value="" />
这篇关于用于格式化输入框的HTML5模式取日期mm / dd / yyyy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文