Restrict input charaters in textbox

C

Cylix

I would like to let the client input numeric, "," and "-" in the
textbox,
all the other else charater will take no effect on the value of the
textbox.

How can I do so?

Thanks a lot!
 
R

rowe_newsgroups

I would like to let the client input numeric, "," and "-" in the
textbox,
all the other else charater will take no effect on the value of the
textbox.

How can I do so?

Thanks a lot!

The "standard" way is to handle the textbox's keydown, keypress, or
keyup events and trap the invalid keys there and prevent them from
going into the textbox. You may also have to trap paste events - it's
been a while and I don't remember if the above will catch pasted text
or not.

Thanks,

Seth Rowe
 
M

Mr. Arnold

Cylix said:
I would like to let the client input numeric, "," and "-" in the
textbox,
all the other else charater will take no effect on the value of the
textbox.

How can I do so?

Thanks a lot!


You put something like the code below in the Textbox Keydown event

If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
'cancel keys
e.Handled = True
End If
 
C

Cylix

Sorry about such silly question,
I just don't know that I can done the task by e.handled = true.

Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top