VitorLuizC / brazilian-values

🇧🇷 Funções de formatação, conversão e validação para valores, documentos e outras unidades usadas no Brasil. Como CEP, CNPJ, CPF, BRL (R$), datas, números etc.
MIT License
537 stars 38 forks source link

isPhone not working? #36

Closed guitexa closed 3 years ago

guitexa commented 4 years ago

Hi guys, I'm very proud to find a solution so good made by Brazilians.

I'm trying to use the function isPhone but I don't know if I'm using this wrong, but it's not working as well.

When I type a mobile phone starting with 9 the mask works fine but the state not, and the validation not work because of that. 🤔

See this gif and the code working on SandBox.

phone

https://codesandbox.io/s/shy-surf-4bo20

VitorLuizC commented 4 years ago

Hi, @guitexa! Thank you

That's happening because you're formatting value before display it, instead of formatting value before set in the state. So in your state you have latest formatted value instead of current one.

isPhone checks if value matches phone number format in a huge range of formats, but (99) 9999-99999 isn't one of them. I can add it, but don't seems to me an used format for phone numbers, do you agree?

I've updated your example to set formatted value in the state, and it seems to work fine.

https://codesandbox.io/s/brazilian-values-phone-formatter-and-validation-usages-with-react-4tq9m?file=/src/App.tsx

guitexa commented 3 years ago

Hi @VitorLuizC, thank you so much for answering, I'm new with programming and I didn't think about that, rsrs, it's work very well here.

Have a nice day! 🙏🏼