cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nealhicks1
Level: Powered On

Trying to convert user inputted numbers into phone number format in PowerApps form

Hello everyone,

 

Just as a disclaimer, I have been working on this issue for the past few hours, and have done extensive research and basically read through every bit of information I could find, but I am still having trouble.

 

I have a PowerApps form that is connected to a SharePoint Online list. We have a phone number field, and I am trying to basically transform the numbers people input into the US xxx-xxx-xxxx format. I've tried using a bunch of different TextFormat.Number related modifications, but to no avail. I've also tried converting the input method/type to Text, and using TextFormat.Text=Text(Value(DataCardValue6),"[$-en-US](000)-000-0000").

 

Anyways, I'll be incredibly grateful for any help that anyone can provide. Thank you so much in advance! 

 

Edit: I've also tried TextFormat.Text=Text(Value(DataCardValue6.Text),"[$-en-US](000)-000-0000"). And a lot of variations on this. I keep getting exceptions, so I obviously don't know what I'm doing. 🙂

3 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

You can use it with an If condition in the OnSelect property of Submit button/icon. If the format is true it process SubmitForm otherwise it returns false.

 

If(IsMatch(PhoneNumberField.Text, LeftParen & Digit & Digit & Digit & RightParen & Hyphen & Digit & Digit & Digit & Hyphen & Digit & Digit & Digit & Digit), SubmitForm(EditForm), false)

This isn't to user friendly because the user doesn't know why the form wasn't saved. To make this more user friendly you would need to add a label to the form to display the error message. Then you would need to replace false in the If condition with some code that would make the error message label visible.

 

 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

Highlighted
Meneghino
Level 10

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

To enhance what @Jeff_Thorpe is suggesting, I would say that you could place the IsMatch expression in the DsiplayMode property of the submit button, so that it is disabled unless the input text is in the format you want.  This way the button is not pushable.

Something like this for the DisplayMode property:

If(IsMatch(PhoneNumberField.Text, LeftParen & Digit & Digit & Digit & RightParen & Hyphen & Digit & Digit & Digit & Hyphen & Digit & Digit & Digit & Digit), DisplayMode.Edit, DisplayMode.Disabled)

View solution in original post

Meneghino
Level 10

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

10 REPLIES 10
Meneghino
Level 10

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

Hi @nealhicks1

 

Which of the following are you tring to do?

 

1) Ensure that the input is in the format (xxx)-xxx-xxxx and only accept such input

OR

2) Accept any reasonable input (like 1234567890) and convert it to (123)-456-7890 when updating the SP list

 

The first task is obviously much easier. All it requires is to have your text input in text mode and use the IsMatch function in a simple way.  For example to enable the save button (via the DisplayMode property) only if IsMatch is positive.

 

The second task requires to define which patterns are acceptable and have a correspondingly complex IsMatch condition or series of conditions to enable the save button.  Then you will need a parsing function using string functions depending on the pattern of the input.

 

Hope this helps

nealhicks1
Level: Powered On

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

Hello @Meneghino,

 

Thanks for the response! Smiley Happy

 

I'm not strong with the coding, so I would vote on whichever option would require less coding to get working. 🙂

 

If I were wanting to go with option 1, how do I go about actually implementing the necessary IsMatch condition?

 

Also, I'm having a problem where any inputted numbers are basically turned into.. well, say that 1234567890 is inputted, then it will turn that into 1,234,567,890, displaying commas and everything. So I need to somehow ensure that the numbers are displayed in the 123-456-7890 format.

 

I really appreciate your help with this!

Super User
Super User

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

The phone number field will need to be a text field. The IsMatch function would look like this:

 

IsMatch(PhoneNumberField.Text, LeftParen & Digit & Digit & Digit & RightParen & Hyphen & Digit & Digit & Digit & Hyphen & Digit & Digit & Digit & Digit)

It will return true if it matches the format (###)-###-#### otherwise it returns false.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
nealhicks1
Level: Powered On

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

Apologies for my ignorance, but where exactly do I input that string? I've been looking all through the Properties and Advanced tabs, but I can't seem to find the right place for that. I am very new at PowerApps, so I apologize for the trouble!

 

Also, @Jeff_Thorpe, thanks for helping me out with both my threads. 🙂

Super User
Super User

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

You can use it with an If condition in the OnSelect property of Submit button/icon. If the format is true it process SubmitForm otherwise it returns false.

 

If(IsMatch(PhoneNumberField.Text, LeftParen & Digit & Digit & Digit & RightParen & Hyphen & Digit & Digit & Digit & Hyphen & Digit & Digit & Digit & Digit), SubmitForm(EditForm), false)

This isn't to user friendly because the user doesn't know why the form wasn't saved. To make this more user friendly you would need to add a label to the form to display the error message. Then you would need to replace false in the If condition with some code that would make the error message label visible.

 

 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

Highlighted
Meneghino
Level 10

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

To enhance what @Jeff_Thorpe is suggesting, I would say that you could place the IsMatch expression in the DsiplayMode property of the submit button, so that it is disabled unless the input text is in the format you want.  This way the button is not pushable.

Something like this for the DisplayMode property:

If(IsMatch(PhoneNumberField.Text, LeftParen & Digit & Digit & Digit & RightParen & Hyphen & Digit & Digit & Digit & Hyphen & Digit & Digit & Digit & Digit), DisplayMode.Edit, DisplayMode.Disabled)

View solution in original post

nealhicks1
Level: Powered On

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

Thanks for all the suggestions!

 

So when you say that I could place the IsMatch expression in the DisplayMode property of the submit button, from where do I go about doing that? In the Advanced tab? I am trying to find the right place to insert that IsMatch code, but I am not sure where I should do that.

 

Sorry for the likely extreme level of newbie-ness!

 

 

Meneghino
Level 10

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

nealhicks1
Level: Powered On

Re: Trying to convert user inputted numbers into phone number format in PowerApps form

Thank you very much! I think I'm good with this, now.

 

I appreciate everyone's help!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,058)