Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用date.js是Date.parse确定用户输入字符串(例如'oct 31 12am'与仅'oct 31')是否包含时间值(即是否明确指定时间)的最简单方法。
Date.parse
使用正则表达式检查用户是否输入了上午或下午,如果没有,则给他们一条消息说必须包含它
<script type="text/javascript"> var str= $("#date_input").val; var patt1=/am|pm/gi; if (!str.match(patt1)){ $("#message").text("you must include a time in either 'am' or 'pm' format"); } </script>