Validating Email

While doing some coding the other day I needed an expression to validate email addresses. The trick was that it had to be flexible enough to handle emails in the format of and

Imports System.Text.RegularExpressions

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strEmail As String = ""

        Dim regexp As New Regex("^([\w-]+\.)*?[\w-]+@[\w-]+\.([\w-]+\.)*?[\w]+$")

        If regexp.IsMatch(strEmail) Then

            MsgBox("Valid Email")


            MsgBox("Invalid Email")

        End If

End Sub