How to validate email address in VB.NET

An email address typically consists of two parts: the local part before the @ sign and the domain name after the @ sign. The local part identifies the specific user or recipient, while the domain name represents the destination where the email message will be sent.

Validating email addresses against specific restrictions can be a complex task, often requiring the use of lengthy regular expressions. Fortunately, the .NET Framework offers a robust set of regular expression tools that simplify the process of creating, comparing, and manipulating strings. These tools also enable efficient parsing of large amounts of text and data to search for, remove, and replace text patterns.

feedback@net-informations.com

Regex.IsMatch method

One useful method provided by the .NET Framework is the Regex.IsMatch method. This method determines whether a given regular expression pattern matches a specified input string. The pattern parameter is composed of various elements of the regular expression language, symbolically describing the pattern to be matched within the string.

Regex.IsMatch("feedback@net-informations.com", pattern)

To validate an email address using regular expressions in VB.NET, you can use the Regex.IsMatch method. This method evaluates whether the email address matches the specified pattern, allowing you to verify its validity based on the defined regular expression.

Full Source VB.NET
Imports System.Text.RegularExpressions Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim pattern As String pattern = "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" If Regex.IsMatch("feedback@net-informations.com", pattern) Then MsgBox("Valid Email address ") Else MsgBox("Not a valid Email address ") End If End Sub End Class