String validating

Craig

Well-known member
Joined
Oct 15, 2005
Messages
110
Location
United Kingdom
Programming Experience
Beginner
Hi All.

I need to be able to check if a text box is containing only the following characters:

0-9 . / \ : - + and space


But im not sure how to do this :confused:

Thanks in advance
 
Last edited:
one way would be to handle it's keypress event:
VB.NET:
Private Const strValidChars As String = "0123456789 /\+-.:"

Private Sub Textbox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress
  If Asc(e.KeyChar) <> Keys.Back Then
    If InStr(strValidChars, e.KeyChar) = 0 Then e.Handled = True
  End If
End Sub
 
Back
Top