This routine DOES NOT check that the date or time input values are valid, just that they match the required format (d/m/y and h:m). Once you're in control of the input format, it's a lot easier to check that the values are actually valid.The function has been improved now so that the day, month and year values are checked to ensure that they're in the right ball-bark (ie. Also the year must be between 1902 and the current year.The return value is displayed next to the input field: Other actions could also be taken such as disabling form submission until there is a valid date. The relevant portions of the HTML are as follows: .
For the time check, the array returned includes the hour (pos 1), minutes (pos 2) and, optionally, the am/pm string (pos 3).Each of these values is then tested against an allowed range (days: 1 - 31; months: 1 - 12; years: 1902 - 2019; and so on).