I have the following code. I would like to perform a if then check via a button click before the user processes the information.
Private Sub TestBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestBTN.Click
If TBSearch.Text = "" & ".exe" Or TBSearch.Text = "" & "" Or TBSearch.Text = ".""*" & ".**" Then TBSearch.BackColor = Color.Aqua Else TBSear开发者_JAVA百科ch.BackColor = Color.Red
End Sub
I would like it to just check to see if the text box info has been entered in one of three formats.
1)blah.blah
2)blah*.blah
3)blah*.*
I hope I explained this right.
You can use regular expressions:
(System.Text.RegularExpressions.Regex)
Dim re As New System.Text.RegularExpressions.Regex("^[^\*]+(\*?\.[^\*]+|\*\.\*)$")
If re.IsMatch(TBSearch.Text) Then
TBSearch.BackColor = Color.Aqua
Else
TBSearch.BackColor = Color.Red
End If
^[^\*]+(\*?\.[^\*]+|\*\.\*)$
will validate any word of the form: (any character != *) followed by (*.) or (.) followed by (*) or (any character != *)
精彩评论