You can also do using regex in the button click event like below
bool Valid = false;
private void button1_Click(object sender, EventArgs e)
{
Regex rx = new Regex("^[a-zA-Z]*$");
if (!string.IsNullOrEmpty(TxtProjectName.Text))
{
if (rx.IsMatch(TxtProjectName.Text))
{
Valid = true;
}
else
{
MessageBox.Show("Numbers are not allowed.");
TxtProjectName.Clear();
TxtProjectName.Focus();
return;
}
}
else
{
MessageBox.Show("Please enter a project name and click Ok.");
TxtProjectName.Focus();
return;
}
}