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

how to filter out non-digit chars when user writes text to System.Windows.Forms.TextBox

P: n/a
Hi,
how to filter out non-digit chars when user writes text to System.Windows.Forms.TextBox?

Thanks,
Iavmn
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> Hi,
how to filter out non-digit chars when user writes text to
System.Windows.Forms.TextBox?

Thanks,
Iavmn


Subscribe to the TextBox.KeyPress event. Check the character in the event
arguments. If it's a non-digit, set e.Handled=true; and that should prevent
the character from being allowed. You might want to do a beep or something
as well.

Pete
Nov 17 '05 #2

P: n/a
Pete Davis wrote:
Hi,
how to filter out non-digit chars when user writes text to
System.Windows.Forms.TextBox?

Thanks,
Iavmn

Subscribe to the TextBox.KeyPress event. Check the character in the event
arguments. If it's a non-digit, set e.Handled=true; and that should prevent
the character from being allowed. You might want to do a beep or something
as well.

Pete


that worked. thanks
Ivan
Nov 17 '05 #3

P: n/a
Note that this technique only prevents users from manually typing the
non-digit characters in the textbox - they can still paste the non-digit
characters from the clipboard. You might want to also implement an event
handler for the TextChanged property and replace all non-digit characters
there.

"Ivan" <iv*********@dynamic-imaging.com> wrote in message
news:Ot**************@tk2msftngp13.phx.gbl...
Pete Davis wrote:
Hi,
how to filter out non-digit chars when user writes text to
System.Windows.Forms.TextBox?

Thanks,
Iavmn

Subscribe to the TextBox.KeyPress event. Check the character in the event
arguments. If it's a non-digit, set e.Handled=true; and that should
prevent the character from being allowed. You might want to do a beep or
something as well.

Pete


that worked. thanks
Ivan

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.