Restrict user to type 'Arabic' Text in TextBox

Ramy Mahrous 2 Tallied Votes 2K Views Share

1- Handler TextBox Key pressed event handler.

ddanbe commented: Hi Ramy! Nice snippet :) +6
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 < 1569)//the start of ascii codes for Arabic chars.
e.Handled = true;
}
}
ddanbe 2,724 Professional Procrastinator Featured Poster

I consider Arabic caligraphy one of the most beautiful in the world. I even can distinguish some letters in it, although I do not understand Arab, exept for some words like "salaam" etc.
I think you are helping lots of people with your snippet.

Ramy Mahrous 401 Postaholic Featured Poster

Danny, you don't imagine how much I miss you... Welcome back...
I love Arabic, that's why I did this as code snippet to help who want to deal with it, and for sure I'll be happy to find lots of questions about it.
"salaam" or "salam" == greeting words == "Hey, Hello, or bye bye" the origin "Al Salam" == some name of Allah -our God in Islam-
"Salaam" said instead of "Al Salam Alikom" == Peace be upon you.

What I wrote in the TextBox == I love Arabic language :)

Rajesha N 0 Newbie Poster

Dear Ramy Mahrous, I have a problem with typing Arabic text (for Urdu Language) in Textbox. whenever i type arabic text the writing order switches to right to left. but when some non arabic character like space, brackets etc in the textbox the cursor jumps to right most position. can you please help me out. I am doing it in vb.net

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.