hi,
how do i allow only numbers or null allowed to be entered into a textbox?
Printable View
hi,
how do i allow only numbers or null allowed to be entered into a textbox?
Search the forum. You will find loads of responses to this question.
This will only allow numbers to be entered.
VB Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Not Char.IsNumber(e.KeyChar) Then e.Handled = True End If End Sub
You should also allow the backspace key to be pressed.
VB Code:
If Char.IsNumber(e.KeyChar) = False And Asc(e.KeyChar) <> 8 Then e.Handled = True End If