⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 vb 应用实例 简单应用 ddddddddddddddddddddddddddddddddd
💻 VB
字号:
Imports System.Text.RegularExpressions
Imports System.IO
Imports System.Net

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form  "

    Public Sub New()
        MyBase.New()

        InitializeComponent()


    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button4 = New System.Windows.Forms.Button()
        Me.Button3 = New System.Windows.Forms.Button()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.TextBox2 = New System.Windows.Forms.TextBox()
        Me.TextBox3 = New System.Windows.Forms.TextBox()
        Me.TextBox4 = New System.Windows.Forms.TextBox()
        Me.SuspendLayout()
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(205, 104)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(153, 24)
        Me.Button4.TabIndex = 11
        Me.Button4.Text = "替换"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(205, 48)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(153, 24)
        Me.Button3.TabIndex = 10
        Me.Button3.Text = "验证输入E-Mail"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(205, 136)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(153, 24)
        Me.Button2.TabIndex = 9
        Me.Button2.Text = "查找数字"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(205, 16)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(153, 24)
        Me.Button1.TabIndex = 8
        Me.Button1.Text = "验证输入日期"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(10, 16)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(174, 21)
        Me.TextBox1.TabIndex = 12
        Me.TextBox1.Text = "12/25/2005"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(10, 48)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(174, 21)
        Me.TextBox2.TabIndex = 13
        Me.TextBox2.Text = "jack@xxx.com.tw"
        '
        'TextBox3
        '
        Me.TextBox3.Location = New System.Drawing.Point(10, 104)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(174, 21)
        Me.TextBox3.TabIndex = 14
        Me.TextBox3.Text = "12/25/2005"
        '
        'TextBox4
        '
        Me.TextBox4.Location = New System.Drawing.Point(10, 136)
        Me.TextBox4.Name = "TextBox4"
        Me.TextBox4.Size = New System.Drawing.Size(174, 21)
        Me.TextBox4.TabIndex = 15
        Me.TextBox4.Text = "jack123456com789tw"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(373, 182)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox4, Me.TextBox3, Me.TextBox2, Me.TextBox1, Me.Button4, Me.Button3, Me.Button2, Me.Button1})
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "规则表达式 (Regular Expression)"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Regex.IsMatch(TextBox1.Text, "^\s*\d{1,2}(/|/)\d{1,2}\1(\d{4}|\d{2})\s*$") Then
            TextBox1.ForeColor = Me.DefaultForeColor
            MsgBox("验证正确!")
        Else
            TextBox1.ForeColor = Color.Red
            MsgBox("需要输入日期格式 mm/dd/yy ┪ mm/dd/yyyy !")
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Regex.IsMatch(TextBox2.Text, "^([\w-]+\.)*?[\w-]+@[\w-]+\.([\w-]+\.)*?[\w]+$") Then
            TextBox2.ForeColor = Me.DefaultForeColor
            MsgBox("验证正确!")
        Else
            TextBox2.ForeColor = Color.Red
            MsgBox("需要输入 E-Mail 格式 name@domain.com !")
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        MsgBox(Regex.Replace(TextBox3.Text, "\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b", "${day}-${month}-${year}"))
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim r As Regex
        Dim m As Match

        r = New Regex("\d+", RegexOptions.IgnoreCase Or RegexOptions.Compiled)

        m = r.Match(TextBox4.Text)
        While m.Success
            MsgBox("找到数字 " & m.Value & "位于 " & m.Index.ToString)
            m = m.NextMatch()
        End While

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -