• We just launched and are currently in beta. Join us as we build and grow the community.

How to know if Email is Valid or Not in VB.NET

musti 9688

Map Explorer
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
143
Likes
74
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
Hi! this is donbermoy again! :) For now i will teach you how to code for the validation of email address when you input it. Email address has two parts namely the local part of the address which is the part before the @ sign, and the domain name in which the email message will be sent.

So, now let's start this tutorial!

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

2. Next, add a TextBox named TextBox1 for the inputting of an e-mail address and one Button named Button1 that will decide if the email is valid or not. You must design your layout like this:

emaildesign.png


3. Now, put this code in Button1_Click. This will display the result of the valid or invalid email address you've entered in the TextBox.
  1. Imports

    System.

    Text

    .

    RegularExpressions
  2. Public

    Class

    Form1

  3. Private

    Sub

    Button1_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Button1.

    Click
  4. Dim

    expression As

    String
  5. expression =

    "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"
  6. If

    Regex.

    IsMatch

    (

    TextBox1.

    Text

    , expression)

    Then
  7. MsgBox

    (

    "Valid Email address "

    )
  8. Else
  9. MsgBox

    (

    "Not a valid Email address "

    )
  10. End

    If
  11. End

    Sub
  12. End

    Class

Explanation:

We have imported System.

Text

.

RegularExpressions

because we will use regular expression function to commnunicate with our input. We also initialized expression As String to hold the string value of "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$". VB.NET provides an extensive set of regular expression tools that enable to efficiently compare strings as well as rapidly parse large amounts of text and data to search for, remove, and replace text patterns for validating an email address. Regex.

IsMatch

(

TextBox1.

Text

, expression)

- this syntax indicates whether the specified regular expression finds a match in the specified input string of our textbox and compare its regural expression to our variable expression. If the comparing was right, then it will display, "Valid Email address ". Otherwise, it will prompt the user "Not a valid Email address ".

Output:

emailvalid.png

emailnotvalid.png


Download the source code below and try it! :)

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon R. Bermoy

IT Instructor/System Developer/Android Developer

Mobile: 09079373999

Telephone: 826-9296

E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,292

324,186

324,194

Top