HTML5 date input - support partial ISO8601 strings?

Viewed 295

I have an HTML5 date picker <input type="date">

I want people to be able to submit dates in any of these formats:

  • YYYY-MM-DD
  • YYYY-MM
  • YYYY

That is, if they know the full date, they can submit that. If not, just a partial date is fine. This is allowed in ISO8601 parsing rules for reduced accuracy.

At the moment, if the input is partial - like "2020-04" - Firefox treats it as null and doesn't submit anything. Chrome shows a validation error.

enter image description here

Date input does not accept the pattern attribute - so I can't use that.

Is there any way to tell the browser that a partial timestamp is allowed?

0 Answers
Related