Wednesday, August 20, 2008

Only Numbers In Text Box In Vb.Net Windows Based Application

Write this code in the KeyPress event of the text box which you want to accept only numeric values.
If Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57 Then
e.Handled = False
ElseIf Asc(e.KeyChar) = 46 Then
e.Handled = False
Else
e.Handled = True
End If

No comments: