react-input-mask icon indicating copy to clipboard operation
react-input-mask copied to clipboard

how to only allow numbers and uppercase letters?

Open ranyue880809 opened this issue 5 years ago • 4 comments

Hi @sanniassin do you know how to allow only numbers and uppercase letters? When user inputs lowercase, it should automatically converts to uppercase.

ranyue880809 avatar Mar 05 '19 08:03 ranyue880809

This can be implemented using controlled components.

prwinkmr avatar Mar 13 '19 12:03 prwinkmr

would be great if anyone could provide an example

nik72619c avatar Jun 12 '19 06:06 nik72619c

The way I did it was setting the mask prop to a9a 9a9 and then adding text-transform: uppercase CSS to my input element

mryechkin avatar Oct 17 '19 19:10 mryechkin

I did a bit different. Defined beforeMaskedValueChange like so:

beforeMaskedValueChange = function(newState) {
        newState.value = newState.value.toUpperCase();
        return newState;
};

Not sure is it the best possible solution for this case, but it worked for me so far.

shytikov avatar Oct 24 '19 14:10 shytikov