Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deangrant/10198f223182db9b9abd to your computer and use it in GitHub Desktop.
Save deangrant/10198f223182db9b9abd to your computer and use it in GitHub Desktop.
Snippet for validating email address with custom error in Create-EmailHash function
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True, ValueFromPipeline=$True, HelpMessage="Enter an email address to compute hash")]
[ValidateScript({If ($_ -match "\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b") {$True}
Else {Throw "The email address $_ is not a valid email address format."}})]
[String[]]$Email
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment