hi,

how to restrict the text box input to allow user to write only Arabic letters, without english letters or numbers or ponctuation symbols. i searched on the net and i tried this code but it does't do what i want

private void nomTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar)&& e.KeyChar.ToString()!="\b" && e.KeyChar=='a' ) 
                e.Handled = true; 
        }

thanks

Handle Keypressed event of the textbox

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            char lastChar = e.KeyChar;
            //MessageBox.Show(((int)e.KeyChar).ToString());
            if (e.KeyChar != 32 && e.KeyChar !=8) //allows space and backspace
            {
                if (char.IsControl(lastChar) || char.IsDigit(lastChar) || char.IsNumber(lastChar) || char.IsPunctuation(lastChar))
                    e.Handled = true;
                else if (lastChar < 1575)//the start of ascii codes for Arabic chars.
                    e.Handled = true;
            }
        }
Attachments Arabic_question_on_Dani.png 37.07 KB

thank you so much but there is a little problem: the arabic letters in the (w,x,c) keys of keyboard can't be entered
in textbox

thanks again

i find the solution we just change the start of ascii code to 1569 :

else if (lastChar < 1569) //the start of ascii codes for Arabic chars.

thanks a lot again you really help me

This question has already been answered. Start a new discussion instead.