Search code examples
c#stringletters-and-numbers

How to find how many numbers and letters are on a string


I'm validating passwords. I need to check how many letters and numbers there are in a password. If there were less than 2 numbers or less than 2 letters, the user should be warned about an invalid password.


Solution

  • For each character in the password, check against the ASCII table and count letters and numbers appearances:

    enter image description here

    Consider adding special characters to the validation.