Validate Email Address Using Regular Expression

Posted: October 14, 2010 in ASP.Net

To validate an email address string, you can try the following:
ASP.Net (Code Behind)

' Function to check that the email is in a valid format
Protected Function ValidEmailFormat(ByVal EmailString As String) As Boolean
    ' Declare variables and check for string pattern
    Dim StringPattern As String = "^[a-z][a-z|0-9|]*([-][[a-z|0-9]+)*([_][[a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$"
    Dim StringMatch As Match = Regex.Match(EmailString.Trim(), StringPattern, RegexOptions.IgnoreCase)
    If StringMatch.Success Then
        Return True
        Return False
    End If
End Function

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s