0

How can I make it so that user has to enter YYYY-MM.

Where in the input box, the hyphen already exists and that you have to fill out as seen replacing YYYY and MM but you cannot enter anything else.

input date gives the mm/dd/yyyy format. I want YYYY-MM.

Thomas Charlesworth
  • 1,789
  • 5
  • 28
  • 53

2 Answers2

0

The date input doesn't allow any deviation from the standard styling, therefore this is not possible (to my knowledge) to do in standard HTML, however, you could utilise a standard HTML input, and then use the Masked Input Plugin by Digital Brush (using Javascript) to mask the input format.
For example:

$("#input").mask("9999-99");

You can also set your own parameters or custom placeholders using the plugin, more info on this can be viewed on their website.

Zac Webb
  • 653
  • 6
  • 22
0

You can't edit the date type format.

If you don't want to use the date picker that HTML5 gives you for free, then you could create your own input box with regex restrictions.

<form>
  <input type="text" name="input1" placeholder="YYYY-MM" required pattern="[0-9]{4}-[0-9]{2}" />
  <input type="submit">
</form> 

If you want more strict validation (this one only validates that input is a 4 digit number and a 2 digit number separated by a hyphen), refer to this post

Regex date validation for yyyy-mm-dd

You can play around with the code here: https://jsfiddle.net/bowenyang/oth9b8o7/

Community
  • 1
  • 1
Bowen Yang
  • 146
  • 1
  • 9