Mask for textbox

I will say first and foremost that as long as I have been coding, regex in general still makes my eyes bleed. So this may be a simple answer to a dumb question. I have a series of textboxes for the purpose of defining the size of a new drive on a VM. I would like them to be filtered to only numbers, max length of four (e.g. 1000 GB or less). From the docs I got a mask for generating a phone number, and have been playing around with that, but cannot get the syntax just right. Below is the code that I am using:

New-UDTextbox -Label "Drive 3 Size" -Id "Drive3Size" -Mask @('/\d/', '/\d/', '/\d/', '/\d/')

This seems to create 4 columns, however - when you enter one number the focus is lost, and you have to click back into the field to type the next. I noticed even using the -Mask example in the docs for a phone number, you have to keep clicking back in the field after each number input. I am looking instead for something the end user can just type the number out, instead of having to click back into the field multiple times, but weeds out any alpha characters on the chance they type 50GB (I realize I can always filter on the .value later as a last resort). I’ve tried some of the following, but just cannot seem to hit on the right syntax:

'/\d\d\d\d/' #Types nothing
'/\d/', '/[1-9]/', '/\d/' #Works, but similarly creates columns
Product: PowerShell Universal
Version: 1.5.8

Just as no-one chipped in yet, I just used an online regex tester https://regex101.com/ and this seems to match one to four numbers:-

^([0-9]{1,4})$

Hope this helps

Thanks for the response. I tried the below:

New-UDTextbox -Label "Drive 3 Size" -Id "Drive3Size" -Mask @('^([0-9]{1,4})$')

but this just set the element value to ‘^([0-9]{1,4})$’. In reading the docs, it says you have to use JavaScript syntax and start/end each regex with ‘/\d/’, so I tried:

... -Mask @('//^([0-9]{1,4})$//')

but this did not work either. Thus far, the closest I have come is this:

...-Mask @('/\d/', '/\d/', '/\d/', '/\d/')

but this creates the column effect. Perhaps @adam will wander by and have a thought.

If you look at the documentation you see that each regex expression has to be in a single quote, and separated by a comma. So what I posted is valied JS regex expression, but you would then have to separate that with single quotes and commas from what I am seeing on the documentation page
https://docs.ironmansoftware.com/dashboard/components/inputs/textbox#mask
so why don’t you keep it simple, from the example on the page above the below is only allowing numbers…

'/[1-9]/'

so then maybe try to mix that with

-Mask @('/[0-9]/','{1,4}')

I need to upgrade to say for sure but I think

won’t work as it is several regex expressions making that formula, and it looks as if each regex has to be put into it’s on single quotes…my gut feeling anyways… :thinking:

Thanks, I will keep playing around with it. I know this:

-Mask @('/[0-9]/','{1,4}')

simply sets {1,4} as the element’s value. I have tried several permutations of the ‘{1,4}’ such as ‘/{1,4}/’ but actually get an “invalid expression” error on most of them. I do know that this works:

-Mask @('/[0-9]/', '/[0-9]/')

but again, you create the column effect where the user has to click back into the field each time they input a number. I will keep playing with it, but may just have to leave it as a free-form text field and deal with any unwanted characters after the fact.