HS Banner
Back
Regular Expressions In VB.Net

Author: Guitarman 05/01/2021
Language: Visual Basic .NET
Tags:


Description:

This is a function I wrote to check for a valid email address.

Article:

Imports System.Text.RegularExpressions
Public Class Regular_Expressions
    Public Const EmailExpressions As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
    Public Const NumberExpressions As String = "^(0?\d|[12]\d|3[0-4])?\.\d\d$|^35\.([02]\d|3[05])$"

    Public Shared Function ExpressionsCheck(ByVal Value As String, Optional ByVal Pattern As String = EmailExpressions) As Boolean
        Register.timer1.Start() 'See if the key code is there

        'Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
        Dim emailAddressMatch As Match = Regex.Match(Value, Pattern)
        If emailAddressMatch.Success Then
            ExpressionsCheck = True
        Else
            ExpressionsCheck = False
        End If
    End Function

End Class



Back
Comments
Add Comment
There are no comments yet.