Comments (3)
Hey!
Thank you for taking your time checking out this project!
Even though, I don't think that is, currently, a problem. 24843803480
wouldn't be an invalid CPF because the special chars are all optional (see the question marks in the regex: ^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$
). To prove my point, I added {"24843803480", true}
to the test cases in TestIsCPF
(cpfcnpj_test.go#7
), ran it locally and all the tests passed. 👍
Did you experience any problem while using the lib?
About your tip: I didn't want to clean it because that would prevent the code to validate invalid special characters (actually, that was the old solution). Those documents have a specific mask/format, and that should be validated too, not just the numbers. For example, and ignoring the consistency of the numbers here, 000.000.000-00
is a valid format, but 00.00.00.00-000
is not.
There is still room for improvement. The current solution checks every special char individually, which can lead to return something like a 000.000.00000
as a false positive, since it's not in the correct format. Still, I didn't want a giant complex regex pattern... Do you have anything in mind for that?
I'll let this issue open for awhile if there's anything more you'd like to discuss! ;)
from brdoc.
Awesome, you're right, I didn't notice the ?
at your regex, you can close the issue.
About your specific case 000.000.00000
maybe you can match as a group and test two specific cases using OR operator, you will test a case with special characters and other without special characters
(^\d{3}\.\d{3}\.\d{3}\-\d{2}$|^\d{3}\d{3}\d{3}\d{2}$)
, you can optimize this regex, to this (^\d{3}\.\d{3}\.\d{3}\-\d{2}$|^\d{11}$)
, at this case you don't need to use ?
from brdoc.
That is a solution! I'll think about implementing it.
I'll close this issue for now, since the original problem was resolved.
Thank you for your help! 😉
from brdoc.
Related Issues (11)
- Add package to awesome-go HOT 2
- CEP Validator HOT 1
- Inscrição Estadual Validator HOT 6
- Renavam Validator HOT 3
- CNH Validator HOT 2
- CNH com hífen HOT 2
- Dúvida sobre validação do cep HOT 7
- Suporte a validação de número de celular/telefone HOT 1
- Validador de RG HOT 1
- Bug com IsCNPJ para CNPJ 39591842000010 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brdoc.