I want to prohibit the input of non-Latin characters when entering username and password during registration.
I make registration in WPF and I want to warn the user that input in other languages ββis prohibited.
I would do like this
private void textBox1_TextChanged(object sender, EventArgs e) { if (!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "^[a-zA-Z]") && textBox1.TextLength!=0) { MessageBox.Show("ΠΠ²ΠΎΠ΄ Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ ΡΠΎΠ»ΡΠΊΠΎ Π½Π° Π»Π°ΡΠΈΠ½ΠΈΡΠ΅"); textBox1.Text.Remove(textBox1.Text.Length - 1); } } Here is the working code for the WinForm project. I think for wpf you will remake without difficulty. The code is working.
private void FIOTextBox_TextChanged(object sender, EventArgs e) { bool BadSymbolsInside = false; for (int i = 0; i < FIOTextBox.Text.Length; i++) { if (!((FIOTextBox.Text[i] > 'A' && FIOTextBox.Text[i] < 'Z') || (FIOTextBox.Text[i] > 'a' && FIOTextBox.Text[i] < 'z') || //ΠΡΠ±ΡΠ΅ Π΄ΡΡΠ³ΠΈΠ΅ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½Ρ ΡΠΈΡΠ»Π΅ ΠΏΠΎ Π²Π°ΡΠ΅ΠΌΡ Π²ΠΊΡΡΡ || (FIOTextBox.Text[i] > '0' && FIOTextBox.Text[i] < '9'))) { BadSymbolsInside = true; } } if (BadSymbolsInside) { MessageBox.Show("ΠΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΡΠ΅ Π½Π΅Π΄ΠΎΠΏΡΡΡΠΈΠΌΡΠ΅ ΡΠΈΠΌΠ²ΠΎΠ»Ρ \nΠΠ»Ρ Π»ΠΎΠ³ΠΈΠ½Π° ΠΌΠΎΠΆΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΡΠΎΠ»ΡΠΊΠΎ Π»Π°ΡΠΈΠ½ΡΠΊΠΈΠ΅ Π±ΡΠΊΠ²Ρ ΠΈ ΡΠΈΡΡΡ"); FIOTextBox.Text = ""; } } Source: https://ru.stackoverflow.com/questions/330898/
All Articles
||? - VladD