Home > Uncategorized > Using Wildcard Masks to filter black or white email addresses

Using Wildcard Masks to filter black or white email addresses

By using Wildcard mask you can quickly and easily verify bad emails and good emails according to you defined BlackList and WhiteList. To do that, you need to specify the lowest ValidationLevel.

The example below shows how to verify bad and good emails using ComponentSoft email validator library.

C# Copy Code
static void Main()
{
string email = test@adomain.com;
string emails = vietnt@hanoictt.com;jimmy@adomain.com;
EmailValidator em =
new EmailValidator();
em.ValidationLevel = ValidationLevel.Lists;
em.EmailValidated += em_EmailValidated;
// You can use wilcards to validate email addresses
em.BlackList.Add(“te??@*.com”);
em.BlackList.Add(
“*@adomain.com”);
em.WhiteList.Add(
“*@hanoictt.com”);
// Validate an email
em.Validate(email);
// Validate a list of emails
em.ValidateEmails(emails);
}
static void em_EmailValidated(object sender, EmailValidatedEventArgs e)
{
Console.WriteLine(e.ValidatedLevel == ValidationLevel.Success ? (e.EmailAddress +
” is a valid email”) : (e.EmailAddress + ” is an invalid email”));
}
VB.NET Copy Code
Sub Main()
Dim email As String = test@adomain.com
Dim emails As String = vietnt@hanoictt.com;jimmy@adomain.com
Dim em As New EmailValidator()
em.ValidationLevel = ValidationLevel.Lists
AddHandler em.EmailValidated, AddressOf em_EmailValidated
‘ You can use wilcards to validate email addresses
em.BlackList.Add(“te??@*.com”)
em.BlackList.Add(
“*@adomain.com”)
em.WhiteList.Add(
“*@hanoictt.com”)
‘ Validate an email
em.Validate(email)
‘ Validate a list of emails
em.ValidateEmails(emails)
End Sub
Private Sub em_EmailValidated(ByVal sender As Object, ByVal e As EmailValidatedEventArgs)
If e.ValidatedLevel = ValidationLevel.Success Then
Console.WriteLine(e.EmailAddress &
” is a valid email”)
Else
Console.WriteLine(e.EmailAddress &
” is an invalid email”)
End If
End Sub

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.