E-mail address checker

It has been an while since I posted an update. It’s been pretty busy at work (mostly powershell related, thus a lot of fun to do) and have been busy working on several scripts to automate my work. Some of them I will also share here, like this nice little script to validate an e-mail address.

I needed a script to validate an e-mail address, but since the tlds can be pretty ‘random’ nowadays, I didn’t want to just implement the rfc822 regex and hope for the best, but wanted to validate the TLD as well. Since I’m already validating the TLD, I think I can also do with a less comprehensive regex to check for mailaddress standards.

Thus I came up with the following script. First I download the list of current TLDs and update this file every month. Then I check if the TLD(s) of the given e-mail address(es) are in the list of TLDs. Once this is done, the simple e-mail address regex checker will validate the rest of the address.

You can find the script here: EmailAddressChecker.ps1

So the main important lines in the script are:

$TldUrl = http://data.iana.org/TLD/tlds-alpha-by-domain.txt(link to list of current TLDs)

$Regex = “^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$” (E-mail address regex, check for allowed characters before the @ and after. After the dot it can only contain letters, with a minimum length of 2 and a maximum lenght of 63, according to RFC standard: https://tools.ietf.org/html/rfc1034)

At this moment the script only outputs that the TLD exists. You can replace Write-Output “TLD exists for $MailAddress For anything you like it to do after the TLD validation has been done.

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: