How to Check if a String Contains Numbers in Power Automate?

Do you need to check if a string contains numbers? This Power Automate tutorial is for you; here, I will explain how to check if a string contains numbers in Power Automate.

Scenario:

Recently, I got a requirement to check if a string contains numbers using a flow; for example:
If the input string value contains numbers, then it returns the string containing numbers.

Input string value = 'Text123' 
Output: True (The input string contains numbers)

Similarly, if the input string doesn’t contain numbers, then it returns the string doesn’t contain any numbers.

Input string value  = 'Text' 
Output: False (The input string doesn't contain any numbers)

Now, we will create a flow to check if a String contains Numbers in Power Automate.

Check if a String contains Numbers using Power Automate

Let us see how to check if a String contains Numbers using Power Automate flow

To achieve this, follow the below steps:

  • Create an instant cloud flow with a Manual trigger, Expand the trigger action, and add the Text input as highlighted below:
How to check if a String contains Numbers using Power Automate flow
  • Add an initialize variable action from the action trigger, and provide the below parameters.
    • Name – Enter the variable name
    • Type – Choose the variable type as Array
    • Value – Pass the below expression to create an array of numbers from (0 to 9)
createArray('0','1','2','3','4','5','6','7','8','9')
power automate check if string contains numbers
  • Select + new step and choose the Select data operation; in the from section, pass the below expression to find the length of the input string.
range(0,length(triggerBody()['text']))

In the Map section, switch the map to the text mode and use the below expression, which slices the input string value and checks with the initialized variable number values.

See also  Power bi slicer panel - How to use

If the input string value contains any numbers, then it returns a true value; else it returns a false.

if(contains(variables('Numbers'),slice(triggerBody()['text'], item(), add(item(), 1))), true, false)
How to check if a String contains Numbers in Power Automate
  • Add a new step and check the condition of the outputs of the select data operation containing the value true; if yes, add a compose data operations, then the input string contains numbers. If no, the input string doesn’t contain any numbers.
body('Select')
check if a String contains Numbers in Power Automate
  • Save and run the flow by selecting the run flow option.

Test case-1:

Here, I have passed the input string as EnjoySharePoint123

check if a String contains Numbers in Power Automate flow

Once the flow runs successfully, then in the compose data operation, we can see the result as expected.

check if string contains numbers using flow

Test case-2:

Here, I have passed the input string as EnjoySharePoint

How to check if a String contains Numbers using Power Automate

Once the flow runs successfully, then in the compose data operation is as expected.

check if string contains any number using Power Automate flow

This is how to check if a string contains numbers using the Power Automate flow

Conclusion

I hope you understand how to check if a string contains numbers in Power Automate flow. Here, I have shown you how to check if a string contains numbers or not using flow with an example.

You may like:

>