Thursday, April 29, 2010

Email Validation Entered Into Textbox Tutorial Visual Basic {VB.net}

Hi all once again, today i will be teaching u all how to validate the email entered into a text box or label to be in correct email format. We will be using Regex to make email validation.

{Note: Remember to rename the "Name" of the textbox1 to "email" or it won't work and please check all the names of the labels from the video tutorial or alter it according to your project.}

Codes:

'General Declarations
Imports System.Text.RegularExpressions
____________________________________________________________________

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FoundMatch As Boolean
Try
FoundMatch = Regex.IsMatch(email.Text, "\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase)
Catch ex As ArgumentException 'Syntax error in the regular expression
End Try
If Not FoundMatch Then
Label2.Text=("Not a Valid Email Address")
Else
Label2.Text("Valid Email Address")
End If
End Sub

End Class
_________________________________________________________________________

Here is the video tutorial:

1 comment: