Quint van Dijk
Quint van Dijk

Reputation: 362

Validate Pattern on Array Parameter

I have a script that accepts one or more subdomains, I want to validate them but [ValidatePattern()] seems to only check the first item in the array.

The code:

param(
    [ValidatePattern('\w*\.domain\.com')][string]$subdomain
)

This input gets accepted:

.\script.ps1 -subdomain "test.domain.com", "randomstring"

Is there a way to validate every entry in the array?

Upvotes: 2

Views: 1881

Answers (1)

Vincent K
Vincent K

Reputation: 1346

param(
    [ValidatePattern('\w*\.domain\.com')][string[]]$subdomain
)

in your script subdomain parameter doesn't accept multiple values. [string[]]$subdomain

Upvotes: 6

Related Questions