I'm a beginner with ReactJS and I'm trying to set up a mask for the input field of my form.
This mask that I'm trying to configure must be dynamic, because it should work if the field is CPF or CPNJ:
CPF format: 111.111.111-11
CNPJ format: 11.111.111/1111-11
Regex to validate both: /(^\d{3}\.\d{3}\.\d{3}\-\d{2}$)|(^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$)/
I am using react-text-mask to try to configure the mask. I am inserting the CPF and CNPJ regex but the react-text-mask does not recognize it. When the user types more than 11 characters automatically, the mask is in the CNPJ format. Can you tell me how I can do that?
Here's my code I put into codesandbox
Thanks in advance.