0

I want to create an HTML page which includes a form, where one of it cells should be a date of the format 'mm/yy' with a minimum value of the current month (similar to credit card expiration for example).

How can I do it? I haven't found any option using the date/month types, is there any better option than using text with a matching regex like below?

<input type="text" pattern="\d{2}/\d{2}" required>
Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36
dag8336
  • 1
  • 1

1 Answers1

0

I would suggest using "date" type instead. It gives a lot of in-built staff. You can set min and max as well. Here you can find more: https://developer.mozilla.org/ru/docs/Web/HTML/Element/Input/date

Example:

<input type="date"
   value="2018-07-22"
   min="2018-01-01" max="2018-12-31">
Victoria Unizhona
  • 266
  • 1
  • 2
  • 11
  • "date" was my first choice, the problem is that I couldn't find a way to use the format of only MM/YY (no day, only 2 digits for year). Am I wrong? Can it be enforced somehow? – dag8336 Nov 13 '22 at 17:34
  • `type="date"` has locale based input format and that [can not be changed](https://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format) – Justinas Nov 14 '22 at 10:44
  • You can do a little trick as described in this comment -https://stackoverflow.com/a/31162426/12844525 and it will show the thing you want https://jsfiddle.net/g74a3ybo/3/ @dag8336 – Victoria Unizhona Nov 14 '22 at 12:51