By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

Restrict input charaters in textbox

P: n/a
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!

Jul 5 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Jul 5, 5:13 am, Cylix <cylix2...@gmail.comwrote:
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

Jul 5 '07 #2

P: n/a
Hi,

You can search this newsgroup with this problem,

http://groups.google.nl/group/micros...umeric+textbox

There you will find the solution as Seth has written.

Cor

"Cylix" <cy*******@gmail.comschreef in bericht
news:11**********************@z28g2000prd.googlegr oups.com...
>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!

Jul 5 '07 #3

P: n/a

"Cylix" <cy*******@gmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
>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

Jul 5 '07 #4

P: n/a

"Mr. Arnold" <MR. Ar****@Arnold.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>
"Cylix" <cy*******@gmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
>>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!

Sorry, that would be put in the Textbox KeyPress event is the right place.
>
If (e.KeyChar < "0" OrElse e.KeyChar "9") _
AndAlso e.KeyChar <ControlChars.Back AndAlso e.KeyChar <"." Then
'cancel keys
e.Handled = True
End If
Jul 5 '07 #5

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

Thanks a lot.

Jul 6 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.