Limiting textbox input to numbers
-
I have got a textbox that I want to limit to numerical values. How do I prevent the user from entering text? I have set the DataFormat property to "Number", but that doesn't do it. Cheers, Fredrik
Sonork ID: 100.11430:PhatBoy'It is so much simpler to bury reality than it is to dispose of dreams.'
- Don Delillo, Americana -
I have got a textbox that I want to limit to numerical values. How do I prevent the user from entering text? I have set the DataFormat property to "Number", but that doesn't do it. Cheers, Fredrik
Sonork ID: 100.11430:PhatBoy'It is so much simpler to bury reality than it is to dispose of dreams.'
- Don Delillo, AmericanaHi.. Try this: add an event handler to the KeyPress event of the text box:
Private Sub text1_KeyPress(KeyAscii As Integer) If Not (KeyAscii > 47 And KeyAscii < 59) Then KeyAscii = 0 End If End Sub
the code above checks the ascii code of the character and validates the range and sets it to 0 if out of the range of numbers. -
Hi.. Try this: add an event handler to the KeyPress event of the text box:
Private Sub text1_KeyPress(KeyAscii As Integer) If Not (KeyAscii > 47 And KeyAscii < 59) Then KeyAscii = 0 End If End Sub
the code above checks the ascii code of the character and validates the range and sets it to 0 if out of the range of numbers.