Validate a Text File Of Email Addresses
|
EmailValidator can validate a CSV (comma separated values) file of email addresses.
Each email address must be on a line by itself.
For reference, here is an example text file called "members.csv".
user1@hotmail.com,
user2@yahoo.com,
user3@lycos.com,
user4@hotmail.com,
user5@passport.com,
user6@microsoft.com,
user7@aol.com,
user8@hotmail...com,
user9@yahoo.com,
user10@msn.com,
[C#]
using System;
using Neev Software.ASPNET.Components;
namespace test
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
EmailAddressValidator ev = new EmailAddressValidator();
//wire up the event handler
ev.EmailValidationCompleteEvent+= new EmailValidationEventHandler( Validate_OnValidateEmailCompletEvent );
ev.ValidateCSVFile( "members.csv");
Console.ReadLine();
}
static void Validate_OnValidateEmailCompletEvent( object sender, ValidateEmailEventArgs e )
{
if(e.IsValid)
{
Console.WriteLine( e.EmailAddress + " is valid.");
//here is where the database should be updated to reflect a valid email addres
}
else
{
Console.WriteLine( e.EmailAddress + " is not valid");
//here is where the database should be updated to reflect an invalid email address
}
}
}
}
[Visual
Basic]
Imports Neev Software.ASPNET.Components
Imports System.Collections
Module Module1
Sub Main()
Dim ev As New EmailAddressValidator()
'wire up the event handler
AddHandler ev.EmailValidationCompleteEvent, AddressOf Validate_OnValidateEmailCompletEvent
'validate an ArrayList of Emails
ev.ValidateCSVFile("members.csv")
Console.ReadLine()
End Sub
'event handler of that is fired everytime an email address is checked for validation
Sub Validate_OnValidateEmailCompletEvent(ByVal sender As Object, ByVal e As ValidateEmailEventArgs )
If e.IsValid Then
Console.WriteLine((e.EmailAddress + " is valid."))
'here is where the database should be updated to reflect a valid email addres
Else
Console.WriteLine((e.EmailAddress + " is not valid"))
'here is where the database should be updated to reflect an invalid email address
End If
End Sub
End Module
See
Also