Validating Email Address Using Regex or Regular Expression
A tutorial validating email address through textbox using Visual Basic .NET, So it is more on detecting the ‘@’ and the ‘.’ Symbol.
Open your Visual Basic .NET Application.
Step 1:
Create a New Project, go to File Menu and navigate to New > Project then name it ValidateEmail (see Image below)
Step 2:
Next, Add a New Form by navigating in Project Menu and Click Add Windows Form. You can change the name of your form if you want (optional).
Step 3: Add 1 Label, 1 Button and 1 TextBox (Please refer the image below).
Enjoy!!
Open your Visual Basic .NET Application.
Step 1:
Create a New Project, go to File Menu and navigate to New > Project then name it ValidateEmail (see Image below)
Step 2:
Next, Add a New Form by navigating in Project Menu and Click Add Windows Form. You can change the name of your form if you want (optional).
Label Property
Name: Label1
Text: Validate Email:
TextBox Property
Name: txtEmail
Button Property
Name: btnValidate
Text: Validate
Then go to your code editor and paste this code.
Imports System.Text.RegularExpressionsPublic Class frmValidateEmail'Validate Email Address Using RegexPublic Function validateEmail(ByVal emailAddress) As BooleanDim email As New Regex("([\w-+]+(?:\.[\w-+]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7})")If email.IsMatch(emailAddress) ThenReturn TrueElseReturn FalseEnd IfEnd FunctionPrivate Sub btnValidate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidate.ClickIf validateEmail(txtEmail.Text) = True ThenMsgBox("Email is Valid")'proceed and save emailElseMsgBox("Email is not Valid")End IfEnd SubEnd Class
Final runtime output:
Validating Email Address Using Regex or Regular Expression
Reviewed by code-dev
on
1:28 PM
Rating:
No comments: