<input type="date" />
internally handles dates like so:
> xkcd
Therefore your format should be ^\d{4}-\d\d-\d\d$
. Note however that you will need to provide clear instruction to users if their browser doesn't support type="date"
, or provide a JavaScript calendar alternative, otherwise people won't understand!
Due to the current support for type="date"
being so small, it's probably best to use JavaScript and have a hidden input
field to store the YYYY-mm-dd
format date and validate that, while letting the user type freely into the real input field and try to parse that.