27
Views
3
Comments
[Input Mask React] Two Masks to same Input [Input Mask React]
inputmask-react
Reactive icon
Forge asset by João Barata

I have an input field to perform searches that can receive CPF (11 digits) or CNPJ (15 digits) as value. I want to add a Mask so that it is possible to perform the search only if the value entered in the input is 11 or 15 digits.

2022-05-02 13-50-49
Paulo Ritto

Hi @vn_perpetuo ,

Why don't you check the length of your inserted search text on the triggered action? I assume you have some button to trigger the search (or is it in the onChange/onBlur of the input?).

Either way, inside that action you can check for the Length of your search text, using an If statement with Length(SearchText) <> 11 andLength(SearchText) <> 15, and then you act accordingly, do not refresh data/search anything if that's the case. I'm not understanding why you need a mask for it!


Let me know if this helps,

Paulo

2023-08-29 14-56-14
vn_perpetuo

Hi, thanks for the help. 

The reason for wanting to use a mask is so that the values entered are formatted, for example:

CPF: 999.999.999-99

Do you have any idea how I could do this?

2023-08-29 14-56-14
vn_perpetuo

In the case, I'm using one variable to input field.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.