PassValidator: AtLeastTwoDigits Requirement
Explore the process of adding a password rule requiring at least two digits using test-driven development with Go. Learn to write tests that fail first, then code to pass, and finally refactor the implementation using regular expressions to improve clarity and maintainability.
We'll cover the following...
So far, our Validate function has been limited since it can only handle the scenario where the input password is shorter than eight characters. Let’s enrich it with a new requirement.
At least two digits requirement
This requirement states that the password is valid only if it has at least two digits among its characters. If this requirement is not met, the function has to return the password must contain at least 2 numbers error.
The Red phase
To enter into the Red phase, we’ll write a test for the value abcdefgh1: ...