me-me
me-me

Reputation: 5809

react-input-mask customization when user doesn't type 0's

I'm trying to use [react-input-mask] with a mask of

<InputMask mask='99/99/99' maskChar=''/>

This works great if a user types in 02/21/18 but if a user types in 2/9/18 then they get 29/18/ which is not very intuitive.

I'd like for them to get 02/09/18 added for them. Does anyone know if there is a way for me to achieve this. If not maybe someone could point me in the right direction to a possible solution to writing it myself?

Upvotes: 0

Views: 882

Answers (1)

xadm
xadm

Reputation: 8418

You can use beforeMaskedValueChange to append leading zero conditionally on input length. Of course it should be removed when a user enters 6 numbers.

Upvotes: 1

Related Questions