简体   繁体   English

表单中的表单日期验证

[英]Form date validation in a form

I have a form with 2 fields, in one of theme the user will enter a date in the format dd/mm/yyyy and in the other the user will enter a time in the format hh:mm How can I force this fields formats and how can I validate the date field in order to make sure the date entered is valid and its bigger then the current date and the time field in order to make sure it's a valid time. 我有一个包含2个字段的表单,在一个主题中,用户将以dd / mm / yyyy格式输入日期,在另一个主题中,用户将以hh:mm格式输入时间。我如何验证日期字段,以确保输入的日期有效,并且其日期大于当前日期和时间字段,以确保它是有效时间。 I'm using JavaScript in this web site. 我在此网站上使用JavaScript。

For dd/mm/yyyy use 用于dd / mm / yyyy

< input type=date>

For hh:mm: 对于hh:mm:

< input type="time">

Set a processing function on form's onsubmit field. 在表单的onsubmit字段上设置处理功能。 In that function you can get a value of dates ( with help of document.getElementBy* functions ) and compare them with DateTime object( use default constructor to get current date). 在该函数中,您可以获取日期值(在document.getElementBy *函数的帮助下),并将其与DateTime对象进行比较(使用默认构造函数获取当前日期)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM