Hello,
I am receiving a string value in power automate that is a phone number from a field in a ms form, the issue i am facing is some people are inputting stuff like "n/a", "opt out", "email addresses", even their names to a clearly marked telephone Number field, my question is how can i check that the string received in power automate only contains numbers 0 to 9 and the + sign. have been looking for a solution for this for a while so any help would be great.
The solution from ekarim2020 using the Select function did not work for me. When I was entering the formula into the Map field of the Select function, I got an error saying that it was not valid JSON.
After a lot of searching, I found a solution that did work (see the reply from grantjenkins that starts with "Another option is to convert your variable to XML".
Link: https://powerusers.microsoft.com/t5/Building-Flows/Checking-string-value-for-Letters/m-p/1927095/highlight/true#M212141
Hi @Kaptea ,
There is an isInt() function, but this will not work for you as you need to also accept the + (plus) and may be the space character in the phone number string.
I present one method below. The flow examines each character of the phone number for a valid character (valid characters are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, and space). For each character of the phone number, the flow will record a value of true for a valid phone number character, and false for an invalid character. If this list of true/false values contains a false value then the phone number string is not a valid phone number.
These are the actions of the flow:
The varValidChars contains a list of valid characters that make up a phone number:
[
"+",
" ",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
]
Using the SELECT action: we examine each character of the phone number, and record true (for a valid phone number character) or false (for an invalid character):
*FROM:
range(0, length(variables('varPhoneNumber')))
*MAP:
if(contains(variables('varValidChars'), slice(variables('varPhoneNumber'), item(), add(item(), 1))), true, false)
If the output of the SELECT action contains a false value (i.e any invalid character) then this is not a phone number.
You could further improve the flow further by checking if the phone string starts with a + or a number, that it is of a certain length etc.
See: How to Extract Numbers from a String Using Power Automate
Hope this helps.
Ellis
____________________________________
If I have answered your question, please mark the post as ☑️ Solved.
If you like my response, please give it a Thumbs Up.
My Blog Site | Twitter | LinkedIn
stampcoin
91
Michael E. Gernaey
70
Super User 2025 Season 1
David_MA
48
Super User 2025 Season 1