Tool for validating user input in C# console applications.
To use the package install the uk.joshc.InputValidator NuGet package.
Import the package with using InputValidator; where you need it.
All methods can be accessed from the Input class.
Validate that the user is using Y/N terms.
Input.ValidateYN(string displayMessage)Takes a display message, which is displayed to the user.
Returns true for yes, false for no.
Acceptable input from the user is:
- Yes
- Y
- No
- N
Input is not case sensitive.
Inputs can be validated to ensure they the message is within the array.
Input.ValidateArray(string displayMessage, string[] acceptedValues)Takes a display message, which is displayed to the user and a string array including all the values of that are accepted.
Returns a lowercase string with the input if it is accepted.
string mainMenuInput = Input.ValidateArray("What would you like to do?" +
"\n [L]ist current cards in deck" +
"\n [S]huffle Cards in deck" +
"\n [D]eal a card" +
"\n [E]xit",
new string[] { "l", "s", "d", "e" });