VB 检查文本框是否包含特定字母数字格式的文本

VB check if textbox contains text in a specific alphanumeric format

是否可以检查文本框值是否包含特定格式的字母数字:

以两个大写字母字符开头,后跟六个数字

例如:SO123456

我更喜欢后面的签到码

谢谢

一点正则表达式

    Imports System.Text.RegularExpressions

Dim regex As Regex = New Regex("([A-Z]{2})([0-9]{6})")

Dim match As Match = regex.Match(TextBox1.Text)

If (match.Success) Then
MessageBox.Show("Valid")
Else
MessageBox.Show("Not Valid")
End If

也试试这个:

Dim str As String = TextBox1.Text.Trim()
    Dim num As Integer            
    If str.Length = 8 _
    And Convert.ToInt32(str(0)) > 64 _
    And Convert.ToInt32(str(0)) < 91 _
    And Convert.ToInt32(str(1)) > 64 _
    And Convert.ToInt32(str(1)) < 91 _
    And Integer.TryParse(str.Substring(2, 6), num) Then
        MessageBox.Show("Correct id.")
    Else
        MessageBox.Show("Wrong id.")
    End If

希望对您有所帮助。