Click here to Skip to main content
15,896,063 members
Articles / Web Development / ASP.NET

Regular Expression Validator Web Service

Rate me:
Please Sign up or sign in to vote.
3.80/5 (9 votes)
25 Feb 20033 min read 115.2K   251   22  
This is a simple web service that can be used to validade a regular expression.
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtStoMatch As System.Windows.Forms.TextBox
    Friend WithEvents txtSPattern As System.Windows.Forms.TextBox
    Friend WithEvents btnSimpleMatch As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents cbxIgnoreCase As System.Windows.Forms.CheckBox
    Friend WithEvents cbxEMCAScript As System.Windows.Forms.CheckBox
    Friend WithEvents cbxExplicitCapture As System.Windows.Forms.CheckBox
    Friend WithEvents cbxMultiLine As System.Windows.Forms.CheckBox
    Friend WithEvents cbxRightToLeft As System.Windows.Forms.CheckBox
    Friend WithEvents cbxSingleLine As System.Windows.Forms.CheckBox
    Friend WithEvents cbxIgnorePatternWhitespace As System.Windows.Forms.CheckBox
    Friend WithEvents txtMPattern As System.Windows.Forms.TextBox
    Friend WithEvents txtMtoMatch As System.Windows.Forms.TextBox
    Friend WithEvents btnMatchWithOptions As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.txtStoMatch = New System.Windows.Forms.TextBox()
        Me.txtSPattern = New System.Windows.Forms.TextBox()
        Me.btnSimpleMatch = New System.Windows.Forms.Button()
        Me.txtMPattern = New System.Windows.Forms.TextBox()
        Me.txtMtoMatch = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.btnMatchWithOptions = New System.Windows.Forms.Button()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.cbxIgnoreCase = New System.Windows.Forms.CheckBox()
        Me.cbxEMCAScript = New System.Windows.Forms.CheckBox()
        Me.cbxExplicitCapture = New System.Windows.Forms.CheckBox()
        Me.cbxMultiLine = New System.Windows.Forms.CheckBox()
        Me.cbxRightToLeft = New System.Windows.Forms.CheckBox()
        Me.cbxSingleLine = New System.Windows.Forms.CheckBox()
        Me.cbxIgnorePatternWhitespace = New System.Windows.Forms.CheckBox()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox3, Me.txtMPattern, Me.txtMtoMatch, Me.Label3, Me.Label4, Me.btnMatchWithOptions})
        Me.GroupBox1.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.GroupBox1.Location = New System.Drawing.Point(8, 120)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(472, 200)
        Me.GroupBox1.TabIndex = 50
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "MatchWithOptions WebMethod"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtSPattern, Me.txtStoMatch, Me.Label2, Me.Label1, Me.btnSimpleMatch})
        Me.GroupBox2.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.GroupBox2.Location = New System.Drawing.Point(8, 8)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(472, 104)
        Me.GroupBox2.TabIndex = 0
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "SimpleMatch WebMethod"
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(16, 56)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(100, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Text to macth"
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(16, 32)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(100, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Pattern"
        '
        'txtStoMatch
        '
        Me.txtStoMatch.Location = New System.Drawing.Point(120, 48)
        Me.txtStoMatch.Name = "txtStoMatch"
        Me.txtStoMatch.Size = New System.Drawing.Size(344, 22)
        Me.txtStoMatch.TabIndex = 2
        Me.txtStoMatch.Text = ""
        '
        'txtSPattern
        '
        Me.txtSPattern.Location = New System.Drawing.Point(120, 24)
        Me.txtSPattern.Name = "txtSPattern"
        Me.txtSPattern.Size = New System.Drawing.Size(344, 22)
        Me.txtSPattern.TabIndex = 1
        Me.txtSPattern.Text = ""
        '
        'btnSimpleMatch
        '
        Me.btnSimpleMatch.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnSimpleMatch.Location = New System.Drawing.Point(385, 76)
        Me.btnSimpleMatch.Name = "btnSimpleMatch"
        Me.btnSimpleMatch.TabIndex = 3
        Me.btnSimpleMatch.Text = "Validate"
        '
        'txtMPattern
        '
        Me.txtMPattern.Location = New System.Drawing.Point(120, 24)
        Me.txtMPattern.Name = "txtMPattern"
        Me.txtMPattern.Size = New System.Drawing.Size(344, 22)
        Me.txtMPattern.TabIndex = 4
        Me.txtMPattern.Text = ""
        '
        'txtMtoMatch
        '
        Me.txtMtoMatch.Location = New System.Drawing.Point(120, 48)
        Me.txtMtoMatch.Name = "txtMtoMatch"
        Me.txtMtoMatch.Size = New System.Drawing.Size(344, 22)
        Me.txtMtoMatch.TabIndex = 5
        Me.txtMtoMatch.Text = ""
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(16, 32)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(100, 16)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "Pattern"
        '
        'Label4
        '
        Me.Label4.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.Location = New System.Drawing.Point(16, 56)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(100, 16)
        Me.Label4.TabIndex = 4
        Me.Label4.Text = "Text to macth"
        '
        'btnMatchWithOptions
        '
        Me.btnMatchWithOptions.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnMatchWithOptions.Location = New System.Drawing.Point(384, 168)
        Me.btnMatchWithOptions.Name = "btnMatchWithOptions"
        Me.btnMatchWithOptions.TabIndex = 13
        Me.btnMatchWithOptions.Text = "Validate"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.cbxIgnorePatternWhitespace, Me.cbxSingleLine, Me.cbxRightToLeft, Me.cbxMultiLine, Me.cbxExplicitCapture, Me.cbxEMCAScript, Me.cbxIgnoreCase})
        Me.GroupBox3.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.GroupBox3.Location = New System.Drawing.Point(8, 80)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(456, 80)
        Me.GroupBox3.TabIndex = 150
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "Options"
        '
        'cbxIgnoreCase
        '
        Me.cbxIgnoreCase.Location = New System.Drawing.Point(8, 24)
        Me.cbxIgnoreCase.Name = "cbxIgnoreCase"
        Me.cbxIgnoreCase.TabIndex = 6
        Me.cbxIgnoreCase.Text = "IgnoreCase"
        '
        'cbxEMCAScript
        '
        Me.cbxEMCAScript.Location = New System.Drawing.Point(8, 48)
        Me.cbxEMCAScript.Name = "cbxEMCAScript"
        Me.cbxEMCAScript.TabIndex = 7
        Me.cbxEMCAScript.Text = "ECMAScript"
        '
        'cbxExplicitCapture
        '
        Me.cbxExplicitCapture.Location = New System.Drawing.Point(112, 24)
        Me.cbxExplicitCapture.Name = "cbxExplicitCapture"
        Me.cbxExplicitCapture.TabIndex = 8
        Me.cbxExplicitCapture.Text = "ExplicitCapture"
        '
        'cbxMultiLine
        '
        Me.cbxMultiLine.Location = New System.Drawing.Point(112, 48)
        Me.cbxMultiLine.Name = "cbxMultiLine"
        Me.cbxMultiLine.TabIndex = 9
        Me.cbxMultiLine.Text = "MultiLine"
        '
        'cbxRightToLeft
        '
        Me.cbxRightToLeft.Location = New System.Drawing.Point(216, 24)
        Me.cbxRightToLeft.Name = "cbxRightToLeft"
        Me.cbxRightToLeft.TabIndex = 10
        Me.cbxRightToLeft.Text = "RightToLeft"
        '
        'cbxSingleLine
        '
        Me.cbxSingleLine.Location = New System.Drawing.Point(216, 48)
        Me.cbxSingleLine.Name = "cbxSingleLine"
        Me.cbxSingleLine.TabIndex = 11
        Me.cbxSingleLine.Text = "SingleLine"
        '
        'cbxIgnorePatternWhitespace
        '
        Me.cbxIgnorePatternWhitespace.Location = New System.Drawing.Point(320, 16)
        Me.cbxIgnorePatternWhitespace.Name = "cbxIgnorePatternWhitespace"
        Me.cbxIgnorePatternWhitespace.Size = New System.Drawing.Size(128, 48)
        Me.cbxIgnorePatternWhitespace.TabIndex = 12
        Me.cbxIgnorePatternWhitespace.Text = "Ignore PatternWhitespace"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(488, 326)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox2, Me.GroupBox1})
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.Text = "RegExpService Test"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private mRegExpService As RegExpService.RegExpService
    Private mRegOptions As RegExpService.RegOptions

    Private Sub btnSimpleMatch_Click(ByVal sender As System.Object, _
                                                        ByVal e As System.EventArgs) _
                                                        Handles btnSimpleMatch.Click
        Try
            Me.Cursor.Current = Cursors.WaitCursor
            mRegExpService = New RegExpService.RegExpService()
            MessageBox.Show(CType(mRegExpService.SimpleMatch( _
                                                    Me.txtSPattern.Text, _
                                                    Me.txtStoMatch.Text), String), _
                                                    Me.Text)
        Catch exp As Exception
            MessageBox.Show(exp.ToString, Me.Text)
        Finally
            Me.Cursor.Current = Cursors.Default
            mRegExpService.Dispose()
        End Try
    End Sub

    Private Sub btnMatchWithOptions_Click(ByVal sender As System.Object, _
                                                                ByVal e As System.EventArgs) _
                                                                Handles btnMatchWithOptions.Click
        Try
            Me.Cursor.Current = Cursors.WaitCursor
            mRegExpService = New RegExpService.RegExpService()
            mRegOptions = New RegExpService.RegOptions()

            With mRegOptions
                .IgnoreCase = Me.cbxIgnoreCase.Checked
                .ECMAScript = Me.cbxEMCAScript.Checked
                .ExplicitCapture = Me.cbxExplicitCapture.Checked
                .MultiLine = Me.cbxMultiLine.Checked
                .RightToLeft = Me.cbxRightToLeft.Checked
                .SingleLine = Me.cbxSingleLine.Checked
                .IgnorePatternWhitespace = Me.cbxIgnorePatternWhitespace.Checked
            End With

            MessageBox.Show(CType(mRegExpService.MatchWithOptions( _
                                                    Me.txtMPattern.Text, _
                                                    Me.txtMtoMatch.Text, _
                                                    mRegOptions), String), _
                                                    Me.Text)
        Catch exp As Exception
            MessageBox.Show(exp.ToString, Me.Text)
        Finally
            Me.Cursor.Current = Cursors.Default
            mRegExpService.Dispose()
        End Try

    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Sky Brasil
Brazil Brazil
Ricardo Martins
.NET Architect
Brazil

Comments and Discussions