Restrict user to type 'Arabic' Text in TextBox UserPageVisits:1159 active 317 661 DaniWeb 561 60 2011-01-05T12:18:17+00:00

Restrict user to type 'Arabic' Text in TextBox

Ramy Mahrous

1- Handler TextBox Key pressed event handler.

ddanbe commented: Hi Ramy! Nice snippet :) +6
About the Author

Just ask what you need to know...

code snippet
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
char lastChar = e.KeyChar;
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

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.

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 :)

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

Be a part of the DaniWeb community

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