How to apply regex mask to New-UDTextBox?

The documentation gives a pattern matching example, but I can’t figure out how to apply regex to it. It simply starts outputting the regex in the textbox.

New-UDTextbox -Id 'txtEmail' -Label 'Email' -Mask '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'

image

Product: PowerShell Universal
Version: 3.3.2

I can reproduce this. I’ll open an issue for it.

1 Like

To achieve what you are looking for we are going to have to implement a different type of functionality. The problem is that we are using a very popular library called IMask to perform the masking. The problem is that the regex masking is must be able to match all intermediately typed characters before it will allow the text to be entered.

I find this really weird because you can’t actually do a regex match on an email address because adam@ would not match now would adam@ironm. It does work for matching digits or non-whitespace etc. This was not my assumption of how it worked but I was incorrect.

In order to use this regex feature, you can use the forward slash identifiers to more or less instruct IMask that the string is a regex and not a pattern. Notice them on the beginning and end of the mask.

For example, this regex wouldn’t allow any spaces.

New-UDTextbox -Id 'txtEmail' -Label 'Email' -Mask '/^\S*$/'

Thanks Adam. I’ll play around with it to get it “close enough” for now.