How to determine if a string is numeric (in Power Automate)
Updated: Apr 1, 2020
There are a few ways that you could do this. Here I will show you two of my 'go-tos'.
Determining if a string is numeric - method #1
The first technique that I would like to demonstrate uses the error handling feature of Power Automate. With error handling, you can define any number of steps to run after the failure of an action.
To replicate this follow these steps:
Step 1: Initialise a variable called ‘IsInteger’ (type boolean).
Step 2: Initialise another variable called ‘IntNumber’ (type string).
Step 3: Use a Compose action to convert the string value into an integer. Use the expression int(variables(‘IntNumber’))
Step 4: Set the variable IsInteger to false if the above compose step fails.
Also set ‘Configure run after 'has failed’ option to true. See below
Step 5: Finally check the If condition whether IsInteger is true or false. Here set Configure run after properties ‘is successful’ and ‘is skipped’ to true.
Below is the completed flow:
Here are my test results.
If the input string is non-numeric:
If the input string IS numeric:
Determining if a string is numeric - method #2
The second technique I want to show you uses the Try Catch Finally flow action.
If you are from a developer background you will be familiar with try, catch, finally statements in your code. If any failure happens within the Try method, the Catch statements will execute. The Finally block is always executed when the execution leaves any part of the Try…Catch statement.
In Power Automate, this is modelled like so: