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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numbers only in textbox?

Status
Not open for further replies.

Larsson

Programmer
Jan 31, 2002
140
SE
Hi!

How do I set a textbox on a form to receive only numbers not characters?
For example: 56.245 or -562
And not 45k or Hello World!

Thanks for all help, Larsson
 
the easy way would be to put a range validator control linked to the textbox...
Is that what you want? Or are you talking about excluding the keypress action if the key is not a number... ??
 
The second part, avoiding the key press.
I remember from Visual studio 6.0 that it was possible to set a textbox to be a "number" box.

Larsson
 
You don't have that capability in VS.NET anymore. The only way would be the KeyPress event.
Put aside that you have to create such event, then it's just an if condition where you check if the Chr() value (I'm not sure what it's called now in .NET) of the KeyPressed is in between Chr(0) and Chr(9)...

hth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top