Validate email address format with PowerShell

Here’s a handy function you can use in your PowerShell scripts when you need to verify that information contains a valid emails address.

function ValidateEmailAddress {
param (
[string]$EmailAddress
)

    $emailRegex = ‘^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$’
$isValid = $EmailAddress -match $emailRegex

    return $isValid
}

Just call the function and specify the text you want to verify as a parameter like:

ValidateEmailAddress(“director@ciaops.com”)

and you’ll get either True or False.

One thought on “Validate email address format with PowerShell

Leave a reply to g2-b1d355c5a11d58ee23cb39674cb7796f Cancel reply