I have a Textbox elements that I want to accept only byte values. Note that I'm pretty new to c#, so sorry if I'm missing something obvious.
so I have this piece of code
if (!byte.TryParse(last, out num) && last.Length > 1)
{
System.Media.SystemSounds.Asterisk.Play();
zBox.Text = zBox.Text.Remove(last.Length - 1);
}
So, what I want is for users to enter only byte values there, and anything else than numbers to be ignored (deleted and sound played indicating wrong input). The piece of code that is there achieves that with the problem of the first entered value which can be a letter. If I don't use .length > 1 than I get an expection.
What would be the best way to validate if the entered value is a byte type?