Entering 'prompt for user input' action variable only with numbers and a maximum of 4

How can you ensure that in 'prompt for user input' action variable only numbers and a maximum of 4 can be entered?

Menu Field or Slider Field

1 Like

Thanks. Just started with KM. So have a lot of (maybe simple) questions. But what a great program.

The general pattern (which you'll have seen all over the place -- dialogs, web forms, and so on) is to keep repeating the prompt until the input is valid:

Here's an example using your rules:

Prompt Until Valid.kmmacros (4.3 KB)

...where we validate against the regular expression

^\d{1,4}$

"The entire text, from start (^) to end ($) must consist of 1 to 4 ({1,4}) digits (\d)."

You can use all kinds of Conditions to validate the input. The trick is putting the prompt inside the "Until" action so it is shown at least once and will keep prompting until the user gets it right.

Edit: I've just realised I'm reading the OP as "from 1 to 4 numbers" rather than "a number from 1 to 4". For the latter, @ComplexPoint's "list" is the way to go.

1 Like