How do I create a text mask input?

Hello TB Community,

Please, should someone know how to create a number or text mask input, specific for these scenario below?

We have to fields:

One field is a basic select component for person to choose between CNPJ or CPF.

If person choose CNPJ, the second field should be a ##.###.###/####-## (a 14 digit number)
If person choose CPF, the second field shoul be like this ###.###.###-## (a 11 digit number)

Those are specific brazilian tax number, for companies or citizens.

To illustrate better:

CNPJ: 99.999.999/9999-99
CPF: 999.999.999-99

NOTE: I tried to find an API call within Text Utilites pipe, but couldn’t find something useful for it.

I think should be necessary a custom JS code maybe.

Tks in advance!

Regards,
André

Hi Andre, are you using 2 different fields or the same field needs to be using different masking?

If you’re using 2 different fields this can likely be possible by looking at this post:

If you’re using the same field for both it would require a bit extra JS, but certainly is possible.

Let me know if this works or it must be the same field for both CNPJ and CPF

As a side note, you mentioned a pipe. I do see their are API’s where you can return data about a company using the API.

Something like this: https://www.receitaws.com.br/v1/cnpj/27865757000102

If that’s what you’re looking for I’d be delighted to assist in getting that built.