web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Detect if string conta...
Power Automate
Answered

Detect if string contains numbers only

(0) ShareShare
ReportReport
Posted on by 32

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.

Categories:
I have the same question (0)
  • Verified answer
    Ellis Karim Profile Picture
    11,684 Super User 2025 Season 2 on at

    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:

     

    Snag_23e39d0d.png

    Snag_23dab3bd.png

    The varValidChars contains a list of valid characters that make up a phone number:

    Snag_23e5af53.png

     

     

    [
     "+",
     " ",
     "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):

    Snag_23dbd6e1.png

     

     

    *FROM:
    range(0, length(variables('varPhoneNumber')))
    
    *MAP:
    if(contains(variables('varValidChars'), slice(variables('varPhoneNumber'), item(), add(item(), 1))), true, false)

     

     

    Snag_23f92060.png

    If the output of the SELECT action contains a false value (i.e any invalid character) then this is not a phone number.

    Snag_23e2f340.png

    Snag_24088eb1.png

    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

  • Kaptea Profile Picture
    32 on at

    This is a great solution, thanks @ekarim2020 .

  • zz7 Profile Picture
    2 on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard