I need help on a validation

Steven Low

Active member
Joined
Apr 14, 2005
Messages
42
Programming Experience
1-3
Hi Guys
I need help on a validation. I got it to only type number but now I like it to only have 5 numbers and nothing more. How would I do this guys:confused:

VB.NET:
Private Sub tx10_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tx10.KeyPress
If Not e.KeyChar.IsNumber(e.KeyChar) AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
 
I think can be

1) Set the max length of textbox
2) Use

VB.NET:
Private Sub tx10_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tx10.KeyPress
If (Not e.KeyChar.IsNumber(e.KeyChar) AndAlso e.KeyChar <> ControlChars.Back) OR ([SIZE=2][COLOR=#0000ff]ME[/COLOR][/SIZE][SIZE=2].TextBox1.Text.Length > 5)[/SIZE] Then
e.Handled = True
End If
End Sub
 
Back
Top