开发者

Wild Card Parameter for textbox input in VB.net

开发者 https://www.devze.com 2023-03-10 00:46 出处:网络
I have the following code. I would like to perform a if then check via a button click before the user processes the information.

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 != *)

0

精彩评论

暂无评论...
验证码 换一张
取 消