Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How check greek characters in a textbox? 1

Status
Not open for further replies.

assimang

Programmer
Mar 11, 2008
96
0
0
Is there a way to check if greek characters are typed in a textbox and how? There are a few. I want to avoid them all. Which event must I have to use?


Thanks anyone
in advanced.
 
How you do that will depend, to some extent on what character set you are using. However, if, one of the Key events (probably KeyDown or KeyUp would be better than KeyPress - but experiment), you reject all characters with a code greater than 128.

Something like this:

Code:
	Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown

		If CInt(e.KeyCode) > 128 Then e.Handled = True

	End Sub

However, if you need to allow other characters and symbols, have a look at the Character Map program. Under Accessories on the Start Menu goto System Tools and then you will see Character Map. Select Advanced View and then from the pop-up window select Greek. This will enable you to identify all the Greek characters.


Hoped this helps.

[vampire][bat]
 
Thanks earthandfire. I tried it in keydown event and i still can type greek characters in the textbox either directly from keyboard either pressing alt and a number greater than 128.

Temporarily i did this

If e.KeyChar >= "?" And e.KeyChar <= "?" Then
e.Handled = True
ElseIf e.KeyChar = "?" Or e.KeyChar = "?" Or e.KeyChar = "?" _
Or e.KeyChar = "?" Or e.KeyChar = "?" Or e.KeyChar = "?" Or e.KeyChar = "?" Then
e.Handled = True
ElseIf e.KeyChar = "?" Or e.KeyChar = "?" Then
e.Handled = True
End If

in keypress event.
 
How about?

Code:
	Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

		e.Handled = AscW(e.KeyChar) > 128

	End Sub

Hope this helps.

[vampire][bat]
 
That's really great [thumbsup2]

Why the first way didn't work?
 
The first way didn't work because it doesn't see Alt+1234 as a single KeyDown event, instead it sees it as multiple KeyDown events.

I should have thought of that before suggesting that KeyDown or KeyUp would be better than KeyPress!!

[vampire][bat]
 
Doesn't matter earthandfire the substance is that it works.
I asked you to understand the reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top