Search⌘ K
AI Features

PassValidator: NoSpecialCharacter Requirement

Explore how to implement the no special character requirement in a password validator using the test-driven development cycle in Go. Learn to write failing subtests, achieve passing code, and refactor using regular expressions and constants to improve code quality and test coverage.

The Refactor phase Before going ahead and implementing the last feature of the Validate function, let’s recap the scenarios we’ve managed so far:

  • Passwords shorter than eight characters.
  • Passwords with less than two digits.
  • Passwords without any capital letters.
  • Passwords that don’t meet any combination of the previous points.

Now, we can start implementing the last feature.

No special character requirement

The last requirement states that if a password doesn’t contain any special characters (symbols), it should return the password must contain at least one special character error.

The Red phase

As always, let’s ...