Validating Email-Addresses

by Jan 29, 2009

To check for valid email addresses, you can use the .NET Framework type System.Net.Mail.MailAddress and test whether the data can be converted into this format:

function isEmailAddress($object) {
($object -as [System.Net.Mail.MailAddress]).Address -eq $object -and $object -ne $null
}

isEmailAddress "tobias"
isEmailaddress "tobias@powershell.com"
isEmailAddress $null