Validating Email-Addresses

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

Posted Jan 29 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.