Kluckmuck
Kluckmuck

Reputation: 117

Mui Datepicker accepts incorrect format (yyyy-MM-dd)

I'm using Mui datepicker, with the format yyyy-MM-dd. If the user writes the a value with only one day (yyyy-MM-d), like 2020-12-1, this get converted to 2020-12-01.

Is there a way to assert that the user has to write two digits?

Here is a link to the datepicker demo where you can see how it works.

enter image description here

Upvotes: 0

Views: 880

Answers (1)

Hung Vu
Hung Vu

Reputation: 643

You can use third party library to help with form validation. For example, React hook form. DatePicker API exposes inputRef so this is possible.

Upvotes: 0

Related Questions