Visual Basic Valid Email Checker

Introduction: This tutorial is on how to create a simple email checker in Visual Basic. Steps of Creation: Step 1: First we will need a new form with a textbox1 for the email file path, a file full of emails ready for checking, a textbox2 to define the path to save the valid emails and a button to start checking the emails. We will also require the following imports...
  1. Imports System.IO
Step 2: Next lets get all the emails from our list...
  1. Dim emails As New List(Of String)
  2. Dim working As New List(Of String)
  3. Using sr As New StreamReader(TextBox1.Text)
  4.     While sr.Peek <> -1
  5.                 emails.Add(sr.ReadLine())
  6.     End While
  7. End Using
Step 3: Next lets check each email for the @ and . signs...
  1. For Each em As String In emails
  2.     If (em.Contains("@") And em.Contains(".")) Then
  3.         working.add(em)
  4.     End If
  5. Next
Step 4: Finally we need to output the valid emails to our save path (textbox2)
  1. Using sw As New StreamWriter(TextBox2.Text)
  2.     For Each emm As String In working
  3.         sw.WriteLine(emm)
  4.     Next
  5. End Using
Project Complete! That's it! Below is the full source code and download to the project files:
  1. Imports System.IO
  2. Public Class Form1
  3.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  4.         'Dim fo As New OpenFileDialog
  5.         'fo.RestoreDirectory = True
  6.         'fo.Filter = "txt files (*.txt)|*.txt"
  7.         'fo.FilterIndex = 1
  8.         'fo.ShowDialog()
  9.         Dim emails As New List(Of String)
  10.         Dim working As New List(Of String)
  11.         Using sr As New StreamReader(TextBox1.Text)
  12.             While sr.Peek <> -1
  13.                 emails.Add(sr.ReadLine())
  14.             End While
  15.         End Using
  16.         For Each em As String In emails
  17.             If (em.Contains("@") And em.Contains(".")) Then
  18.                 working.add(em)
  19.             End If
  20.         Next
  21.         Using sw As New StreamWriter(TextBox2.Text)
  22.             For Each emm As String In working
  23.                 sw.WriteLine(emm)
  24.             Next
  25.         End Using
  26.     End Sub
  27. End Class

Add new comment