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;
            }
        }

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

commented: vb.net ......code/...... +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.