Form Validation

Works with any validation attribute. Here’s an example of validating a pattern with a server-side regex.

Here’s a link to the issue:

1 Like

Nice! While I see this a super helpful in eliminating dozens of IF statements in my logic, would i be able to use custom error messages, like “Oops, that’s not a valid phone number” rather than a bunch of syntax about regex pattern validation? End users would be kinda confused when they made a mistake, if that makes sense.

Totally agree and I’ll make sure that’s something that get’s implemented as part of this. It’s not currently built into validation attributes in PowerShell but maybe there is something else we could do here.

Maybe a custom attribute would work? Might not work if you have multiple validation attributes.

     [ValidationErrorMessage(''Oops, that's not a valid email address!")]

I think it will be easier for UDInputs using New-UDInputField as we could provide parameters for messages\validation pretty easily.

Any other recommendations on how’d you envision that working would be great.


I have this hooked up. :partying_face:



That’s pretty much exactly what I had in mind, nice work!

Something like this would work. ValidateScript is almost always better than ValidatePattern as you can create your own error messages.

function Test-ValidateScript {
    param (
            if ($_ -eq 'localhost') {
            else {
                throw "Bad computer name"
        [string] $ComputerName