VB.NET - Email Validation Function-VBForums
Results 1 to 9 of 9

Thread: VB.NET - Email Validation Function

  1. #1

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316

    VB.NET - Email Validation Function

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

    VB Code:
    1. Imports System.Text.RegularExpressions
    2.  
    3.     Function EmailAddressCheck(ByVal emailAddress As String) As Boolean
    4.  
    5.         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]$"
    6.         Dim emailAddressMatch As Match = Regex.Match(emailAddress, pattern)
    7.         If emailAddressMatch.Success Then
    8.             EmailAddressCheck = True
    9.         Else
    10.             EmailAddressCheck = False
    11.         End If
    12.  
    13.     End Function
    SCUZ

  2. #2
    New Member
    Join Date
    May 2007
    Location
    Singapore
    Posts
    2

    Re: VB.NET - Email Validation Function

    Quote Originally Posted by scuzymoto
    Simple regular expression I found and have used succesfully to validate emails submitted to my website.

    VB Code:
    1. Imports System.Text.RegularExpressions
    2.  
    3.     Function EmailAddressCheck(ByVal emailAddress As String) As Boolean
    4.  
    5.         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]$"
    6.         Dim emailAddressMatch As Match = Regex.Match(emailAddress, pattern)
    7.         If emailAddressMatch.Success Then
    8.             EmailAddressCheck = True
    9.         Else
    10.             EmailAddressCheck = False
    11.         End If
    12.  
    13.     End Function

    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

  3. #3
    New Member
    Join Date
    Jun 2007
    Posts
    3

    Re: VB.NET - Email Validation Function

    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

  4. #4

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316

    Re: VB.NET - Email Validation Function

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

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

  5. #5
    New Member
    Join Date
    Apr 2010
    Posts
    1

    Re: VB.NET - Email Validation Function

    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

  6. #6
    New Member
    Join Date
    Feb 2011
    Posts
    1

    Re: VB.NET - Email Validation Function

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

    Test_Email@test.com

    -Jay

  7. #7
    New Member
    Join Date
    Mar 2008
    Posts
    8

    Re: VB.NET - Email Validation Function


  8. #8
    New Member
    Join Date
    Dec 2011
    Posts
    14

    Re: VB.NET - Email Validation Function

    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

  9. #9
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    12,434

    Re: VB.NET - Email Validation Function

    Quote Originally Posted by satheeshs View Post
    i want this code invb6.0 help me
    Check the VB6 code bank for the equalivant code.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.