Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am validating numbers typed into a text box but it is not allowing spaces.

What I have tried:

If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 46 Or Asc(e.KeyChar) > 57 Or (Asc(e.KeyChar) < 48 And Asc(e.KeyChar) > 46) Then
e.Handled = True
MessageBox.Show("Invalid character")
End If
Posted
Updated 21-Dec-17 5:23am

1 solution

Exactly the same why you do for letters in your previous question: How to allow backspace and space when validating letters in VB?[^]
Just replace IsLetter with IsDigit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900