Validating e-mail addresses

Hi,

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:
test@@aol.com
test.gmail.com

And I want to add this kind of mail address in the block list:
informações@uol.com.br

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”}
else{“False”}

http://www.regular-expressions.info/email.html

Maybe this

function Validate-Mail{
Param(

       [ValidatePattern(""^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$")]

       ($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 :

\A(?:[a-z0-9!#$%&’+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&’+/=?^_`{|}~-]+)*
| "(?:[\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}
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]
[a-z0-9]:
(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]
| \[\x01-\x09\x0b\x0c\x0e-\x7f])+)
])\z

“scream” !

but the short :

\A[a-z0-9!#$%&’+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&’+/=?^_`{|}~-]+)*@
(?:a-z0-9?.)+a-z0-9?\z

or above works in 99% of cases