Skip to main content

Notifications

Community site session details

Community site session details

Session Id : lv84ICShGzF311niGFqJ08
Power Automate - Building Flows
Answered

Detect if string contains numbers only

Like (0) ShareShare
ReportReport
Posted on 13 Dec 2022 10:49:46 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.

  • zz7 Profile Picture
    2 on 01 Apr 2024 at 17:55:05
    Re: Detect if string contains numbers only

    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

  • Kaptea Profile Picture
    32 on 13 Dec 2022 at 22:31:06
    Re: Detect if string contains numbers only

    This is a great solution, thanks @ekarim2020 .

  • Verified answer
    Ellis Karim Profile Picture
    10,940 Super User 2025 Season 1 on 13 Dec 2022 at 20:03:22
    Re: Detect if string contains numbers only

    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

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
stampcoin Profile Picture

stampcoin 91

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 70 Super User 2025 Season 1

#3
David_MA Profile Picture

David_MA 48 Super User 2025 Season 1

Overall leaderboard