There is a piece of code. It allows you to enter only oriental characters (Japanese, Chinese, and the like) into the TextBox. But how to do the opposite? Allow to enter everything EXCEPT for these characters?
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (Regex.IsMatch(textBox1.Text, "[^\u2E80-\u9FFF]"))
{
textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
textBox1.SelectionStart = textBox1.TextLength;
}
}
>Solution :
To allow entering everything except Oriental characters (Japanese, Chinese, etc.), you can modify the regular expression to match any character that is not in the specified Unicode range. You can do this by changing the regex pattern from "[^\u2E80-\u9FFF]" to "[\u0000-\u2E7F\u9FFF-\uFFFF]".
Here is the modified code that allows entering everything except Oriental characters:
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (Regex.IsMatch(textBox1.Text, "[\u0000-\u2E7F\u9FFF-\uFFFF]"))
{
textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
textBox1.SelectionStart = textBox1.TextLength;
}
}
This code uses a negated character class "[^\u2E80-\u9FFF]" to match any character that is not in the specified Unicode range. The range is now inverted to [\u0000-\u2E7F\u9FFF-\uFFFF] to match any character that is not in the Oriental character range. If the input string contains any Oriental characters, the code removes the last character from the TextBox and sets the cursor to the end of the remaining text.