Validating e-mail addresses


I have found this function to validate some mail addresses from a list>

function Validate-Mail{ Param ([String]$Address) ($Address -as [System.Net.Mail.MailAddress]).Address ` -eq $Address -and $Address -ne $null}

But it only works for mail addresses like this:

And I want to add this kind of mail address in the block list:

Since “ç” and “õ” aren’t used on mail addresses.
Need to find a way to block any address with graphic accentuations.

you will need to use a regular expression (Regex) let me do some looking for you.

if($email -match “^[A-Z0-9._%±]+@[A-Z0-9.-]+.[A-Z]{2,}$”){“true”}

Maybe this

function Validate-Mail{


       ($Address -as [System.Net.Mail.MailAddress]).Address `
-eq $Address -and $Address -ne $null}


Mark Hammonds,

Thanks! The first one worked perfectly =]

if($email -match "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$"){"true"} else{"False"}

the long version version of RFC 1035 is :

| "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]
| \[\x01-\x09\x0b\x0c\x0e-\x7f])")
@ (?:(?:a-z0-9?.)+a-z0-9?
| [(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}
| \[\x01-\x09\x0b\x0c\x0e-\x7f])+)

“scream” !

but the short :


or above works in 99% of cases