Restrict input charaters in textbox

  • Thread starter Thread starter Cylix
  • Start date Start date
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!
 
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
 
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
 
Sorry about such silly question,
I just don't know that I can done the task by e.handled = true.

Thanks a lot.
 
Back
Top