If you have a form or survey where users enter data (such as a phone number), you may want to validate that the data entered is correct. Power Automate doesn’t provide a built-in function to extract numbers from a string. In response to a question posted on the Power Automate community forum, I wrote the following custom flow that can parse through a string and extract any numerical values contained within it. While there are various different ways to tackle this issue, I think that the flow presented below is easy to understand and implement.
The Flow
The variable varData stores the string from which we will extract the numerical values.

How it works: the SELECT action
SELECT
FROM:
chunk(variables('varData'), 1)
MAP:
if(isInt(item()), item(), null)
The chunk function in Power Automate can divide or split a string into chunks of equal length. The expression in line 5 above splits a string into chunks of length equal to 1 and returns the results as an array. The Select action will loop through each item of the array, starting from the first character (“1”) and progressing to the last character (“0”). The expression in the Map field (line 9) will act on the each item of the array.

The expression inside the Map field works in text mode and uses the relatively new IsInt() function to determine whether a character is an integer. If a character is an integer it is added to the output of the Select action. If a character is not an integer an empty value (null) is added to the output of the Select action. The resulting output of the Select action is an array containing numbers and null values.
How it works: the Join action
Finally the Join action is used to join all the items of the array into a string while removing any null values:
COMPOSE:
join(body('Select'),'')

Runtime Output

All the characters have been removed and we are left with only numbers:

Leave a Reply