I have textbox1 and i need to allow this textbox1 to accept Arabic characters only
no digit accept also no English characters accept
so that i write in key_up event as following
- private void textBox1_KeyUp(object sender, KeyEventArgs e)
- {
- if (textBox1.Text.Any(char.IsDigit))
- {
-
- textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
- textBox1.Focus();
- }
-
- QrClasses qr = new MatrixBarcode.QrClasses();
- bool b = qr.HasArabicCharacters(textBox1.Text);
-
- if (b == false)
- {
-
- textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
-
-
-
- textBox1.Focus();
-
- }
- else
- {
- textBox1.Enabled = true;
- }
- }
- public bool HasArabicCharacters(string text)
-
- {
-
- Regex regex = new Regex(
-
- "[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]");
-
- return regex.IsMatch(text);
- }
I get Error exception startindex cannot be less than zero (index out of range)
in line
- textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
when try to enter Arabic letters
so that how to solve this problem