Can we restrict user input to only accept numbers?

  • can we restrict user input to only accept numbers?

  • can we restrict user input to only enter 4 digits?

@ANSHUL,

I think restrict is not possible in input dialogue. After enter the input data and store it in a variable. Then you can apply your restrictions.

Regards,
Lakshman Ganta.

Create a loop in the workflow around the input dialogue then have a decision afterwards to ensure your criteria (you could use regex to ensure that the user has only entered 4 digits from 0-9)

You can then feedback in a message box they have entered incorrect input.

3 Likes

As @TimK suggests, you can create a loop after the input has been introduced.
You can use Regex but another approach would be with the IsNumeric method.
Output of input dialog is tmp_InputValue.
Add a check with:
if IsNumeric(tmp_InputValue) Then
Continue
Else
Go back to Input Dialog

If the result is a number, IsNumeric(tmp_InputValue) will result as a True.

For reference, see here: Information.IsNumeric(Object) Method (Microsoft.VisualBasic) | Microsoft Learn

1 Like

The only reason i suggested Regex is due to the multiple criteria, but IsNumber along with checking the length of the string works just as well by doing tmp_InputValue.Length = 4.

1 Like

tmp_InputValue.Length < =4 ?

or is it easy in regx ?

Correct if it is from 0-4 digits. otherwise it is just = 4

For Regex you could use the ‘Is Match’ activity with [1]{4}$


  1. 0-9 ↩︎

how to u amend the regular exp to check if the value is blank? with this regular exp - [1]{4}$ ?


  1. 0-9 ↩︎

Be vary of IsNumeric, it also accepts a ton of number representations. ABCD is also numeric, as a hexadecimal number and it will gladly accept it.
Regex or int TryParse with range check seems most appropriate here, +1 for @TimK

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.