Skip to content

Add ErrorMessage parameter to ValidatePatternAttribute #2719

@powercode

Description

@powercode

The errors provided when a parameter validates a [ValidatePattern("somehorribleregex")] is hard to interpret for the user.

It would be useful to be able to provide a human readable error message when the validation fails. Regexs are powerful, but not readable.

Any yes, even if localization may be an issue, it is still better than the regex. :)

param(
[ValidatePattern('[A-Z]:',  ErrorMessage='The Drive should be specified as a single letter followed by a colon, for example "D:"')]
[string] $Drive,

[ValidatePattern('\\\\\w+\\\w+',  ErrorMessage='The NetworkShare should be specified on the following format: "\\computer\sharename"')]
[string] $NetworkShare
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions