Is it possible to limit the "interval" between two dates in <input type="month">
?
You can use the min
and max
attributes.
So:
<input id="aniversario" type="month" name="aniversario"
min="1900-01" max="1999-12">
If yes, is there any mandatory format we should follow when passing the values that limit?
In the case of [type=month]
, the format must be YYYY-MM
(where YYYY
is year with 4 digits and MM
is the month with two digits).
This "limit" is supported by which browsers and mobile devices?
According to the compatibility table of MDN , the support is not yet complete.
In my Firefox, for example, it did not work. And there is a bug that you have been informed about this input.
Additionally, Internet Explorer and Safari are not supported yet.
On Android, it seems that Firefox is not supported either.
Validation
Inaddition,MDNalertsyouaboutdataentryvalidation:
Bydefault,input[type="month"]
does not apply any validation to the entered values. UI implementations generally do not allow you to enter something other than a date, which is useful, but you can still submit the form with the empty entry or enter an invalid date (for example, on April 32).
Polyfill
I found a Polyfill for input[type=month]
, but it seems to me that it depends on jQuery (which I do not like it very much.)