Validating EMail Address Using RegEx

mpappert

Regular
Joined
Oct 5, 2002
Messages
58
Location
Ottawa, ON, Canada
Not really a question, just some code. A small thanks for all the help I've gotten here, I figured I would post this in case someone else finds themselves needing an email verification routine .. :)

M.

Visual Basic:
Option Explicit On 

Imports System.Text.RegularExpressions

Public Class IsValid

    Public Function emailAddress(ByRef strEmailAddress As String) As Boolean

        '[MP]   Returns True if the E-Mail Address is Valid (Matches Pattern)
        strEmailAddress = Trim$(strEmailAddress)
        Return Regex.IsMatch(strEmailAddress, "^[\w\.\-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$")

    End Function

End Class
 
Back
Top