Answer the question
In order to leave comments, you need to log in
How to enter only letters in textbox?
I can’t figure out how to enter only letters (I forbade spaces through keypress, but I need no characters and numbers to be entered)
here is the textbox code:
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = (e.KeyChar == (char)Keys.Space);
}
private void Button5_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" ^ textBox1.Text.Any(char.IsDigit))
{
MessageBox.Show("Введите имя!\n1.Ваше имя не должно содержать цифр или любых других знаков!\n2.Ваше имя не должно быть пустым!");
}
else
{
//другие условия
}
}
Answer the question
In order to leave comments, you need to log in
string Symbol = e.KeyChar.ToString();
if (!Regex.Match(Symbol, @"[а-яА-Я]|[a-zA-Z]").Success)
{
e.Handled = true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question