In this VB.NET Email Validation example, method calls the Regex.IsMatch(String, String) method to verify that the string confirms to a regular expression pattern.


Imports System.Text.RegularExpressions
Public Class Form1

    Private Sub btnCheck_Click(sender As System.Object, e As System.EventArgs) Handles btnCheck.Click
        Dim emailaddress = txtEmail.Text
        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
            MsgBox("Correct email ID", MsgBoxStyle.Information)
        Else
            'emailaddresscheck = False
            MsgBox("Incorrect email ID", MsgBoxStyle.Exclamation)
        End If
    End Sub
End Class

DOWNLOAD SOURCE CODE

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.