I am currently trying to validate a textbox, so only letters (a-Z) can be entered, with the use of TryParseExact.
I have a code to check a time, although could someone demonstrate how this could be done with letters only.
My code is as follows:
private void textBox2_Validating(object sender, CancelEventArgs e)
{
DateTime dateEntered;
if (DateTime.TryParseExact(textBox2.Text, "HH:mm", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dateEntered))
{
}
else
{
MessageBox.Show("You need to enter valid 24 hour time");
}
}
This checks if all characters in a string
sare a letter:See also: Char.IsLetter Method (MSDN)
If you want to accept only ASCII letters (i.e. a-z and A-Z):