Если вам нужно проверить номера внутри текстового поля имени, то:
try {
string name = textBox1.Text;
Regex regex = new Regex("[0-9]");
if (regex.IsMatch(name)) {
throws new FormatException();
}
int age = int.Parse(textBox2.Text);
MessageBox.Show("How are you today?");
}
catch (FormatException) {
MessageBox.Show("Something went wrong");
}
Вы также должны показать более конкретное сообщение для каждого из случаев.
ОБНОВЛЕНИЕ
Что вы действительно должны делать, это:
var regex = new Regex("[0-9]");
if (regex.IsMatch(textBox1.Text)) {
MessageBox.Show("There was a number inside name textbox.","Error in name field!");
return;
}
try {
Convert.ToInt32(textBox2.Text);
} catch (Exception) {
MessageBox.Show("The input in age field was not valid","Error in name field!");
return;
}