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.
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:
- 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)
- 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.
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.
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)
- 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.
- Save and run the flow by selecting the run flow option.
Here, I have passed the input string as EnjoySharePoint123
Once the flow runs successfully, then in the compose data operation, we can see the result as expected.
Here, I have passed the input string as EnjoySharePoint
Once the flow runs successfully, then in the compose data operation is as expected.
This is how to check if a string contains numbers using the Power Automate flow
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:
- How to Convert String to Float in Power Automate?
- Convert a String to a Decimal Number in Power Automate
- How to Convert a String to an Integer in Power Automate?
- Convert String to GUID in Power Automate
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.