Code Monkey home page Code Monkey logo

Comments (3)

paemuri avatar paemuri commented on May 18, 2024 1

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.

filipesilvaa avatar filipesilvaa commented on May 18, 2024 1

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.

paemuri avatar paemuri commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.