# VBForums CodeBank > CodeBank - ASP / ASP.NET / MVC / Web API >  VB.NET - Email Validation Function

## scuzymoto

Simple regular expression I found and have used succesfully to validate emails submitted to my website.


VB Code:
Imports System.Text.RegularExpressions
     Function EmailAddressCheck(ByVal emailAddress As String) As Boolean
         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(emailAddress, pattern)
        If emailAddressMatch.Success Then
            EmailAddressCheck = True
        Else
            EmailAddressCheck = False
        End If
     End Function

----------


## kaydash

> Simple regular expression I found and have used succesfully to validate emails submitted to my website.
> 
> 
> VB Code:
> Imports System.Text.RegularExpressions
>      Function EmailAddressCheck(ByVal emailAddress As String) As Boolean
>          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(emailAddress, pattern)
>         If emailAddressMatch.Success Then
> ...



Sorry Scuzymoto,

I am still an amatuer at regular expression.
Can you explain the use of ""^[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]$" ?

BlackCat

----------


## biggreen96

bringing it back from the dead, my first post even too. 

I am still an amatuer at regular expression.
Can you explain the use of ""^[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]$" ?

BlackCat and biggreen96

----------


## scuzymoto

An excellent website to describe all you could ever want to know...

http://www.regular-expressions.info/tutorialcnt.html

----------


## raaghav

_Checkout this....
Some Simple Mothod.......
_

Dim Expression As New System.Text.RegularExpressions.Regex("\S+@\S+\.\S+")
        If Expression.IsMatch(txtEMail.Text) Then
            MsgBox("The email address is valid.")
        Else
            MsgBox("The email address is NOT valid.", MsgBoxStyle.Critical, "Invalid Mail ID")
            Exit Sub
        End If

----------


## synersoft

This seems to reject underscores _ in the email address, as in:

Test_Email@test.com

-Jay :Confused:

----------


## robertsams23

check this url

http://net-informations.com/vbprj/co...validation.htm

robert

----------


## satheeshs

Imports System.Text.RegularExpressions
        Function EmailAddressCheck(ByVal emailAddress As String) As Boolean
            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(emailAddress, pattern)
            If emailAddressMatch.Success Then
                EmailAddressCheck = True
            Else
                EmailAddressCheck = False
            End If
        End Function 

i want this code invb6.0 help me

----------


## Nightwalker83

> i want this code invb6.0 help me


Check the VB6 code bank for the equalivant code.

----------

