# How to ensure inputs are numeric values and positive numbers only?

Hi,

I’m trying to create a workflow with two prompts and based on the inputs given, makes some simple math. The workflow has only two constraints:

• The inputs entered, can only be numeric values. The workflow can’t proceed if the values entered aren’t numeric.
• Also, negative numbers aren’t allowed.

So… I started the workflow and it works with the first condition. However, when I try to add the condition of the negatives number being allowed the workflow stops working. Here’s the what I’ve done:

Inside the while, this is the condition I have:

This is the error I’m receiving:

Any ideas of how to overcome this?

@moreirasa1

In the second case you can do two things :

1. Convert the negative value to positive value [ Example : if user enter -45 as input convert this input to positive by using Math.Abs(Variable) and you will get 45 as output]

2. Have one If condition while stating if Variable contains (“-”), Prompt msg that Invalid Input and terminate or continue as per your requirement [ If Condition = Variable.ToString.Contains(“-”)]

2 Likes

You can use generate random number instead of input if not mandatory.
asaign activity

a= new Random().Next(1,100)

1 Like

You can use regular expression to check whether input string is number or not.
In addition, based on your workflow, even if one value is not a numeric, you are asking user to enter both the values. But in a standard solution, you don’t need to proceed further until the first value is valid.

1 Like

Hey @moreirasa1
Just keeping it simple, you will want to check if it’s Numeric before checking if it’s less than 0

The condition can be like this:

If(IsNumeric(sNumberOne) And IsNumeric(sNumberTwo), CInt(sNumberOne)<0 And CInt(sNumberTwo)<0, True)

So if you place that entire line into your condition, it will first check if both values are numeric, then check if they are <0. If they are not numeric it will go to the True side. Basically, I used an inline If statement, useful for making comparisons that need to be a certain type before making.

Regards.

4 Likes

Hey @ClaytonM, thanks!

I liked your solution above the others because it was a very simple approach. Also thanks for your explanation and indeed, it seems to work with your tips. Nevertheless, I found a new solution that I will put here just in case for future knowledge sharing:

Cheers.

1 Like

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