cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Validation for No Special Characters in a Phone Number Text Input

Hello,

 

I have a PowerApp connected to a SharePoint list with a number input box. This textbox is intended for a phone number, but we do not want any special characters. I made the range for the numbers in the SharePoint List 0-9. I tried using the validation:

 

IsMatch(DataCardValue5.Text,".*[\\\"&Char(34)&"/<>!@#$%^&*()].*") 

 

But it still is allowing me to type a period. Is there any way to eliminate the period? 

 

A gif below shows me still able to type the period, but not able to type the - or \ 

 

3F335F20-F0D1-4F42-84E5-02C5E784B5FF.GIF

 

Your help is appreciated! Thank you. 

15 REPLIES 15

@RandyHayes yes, all of that logic checks out. 

 

If the user says yes to phone change but types nothing…that sucks but technically no harm. 


If the user types 1 number, we would like them to type the full number so yes. We need 0-9 for 10 digits (formatted or not) 

 

if it matters, right now the share point column itself is set as a number column but 0 minimum and 9 maximum and no separating commas. I was unsure if single line text input would be better or if it matters. 

Thank you so much, Randy! 

 

 

 

@ElizabethK 

When you say that it is set for 0 as min and 9 as max, then you'll not be able to get what you want as it will only allow a single number between 0 and 9.

Your phone numbers are going to be numeric and much larger than 9!

I would remove the min and max on the column.

 

As a future-thinking concept to keep in mind - phone numbers can get tricky.  In some cases you might need country codes.  In some cases you might need extensions.  Etc...

If you restrict your column to be numeric, then you will need additional columns for the other aspects of the number.  For simplicity, having the phone number as a text column instead, allows you to provide other number details.  Example (123) 456-7890 x123 can be stored as:  1234567890x123 or, depending on the application, 1234567890123 and then 10 digit number assumed and all remaining are extension.  Ex: 12345678904321 can be formatted as (123) 456-7890 x4321

Just mentioning as an FYI so that you don't restrict yourself by the data type.

 

Now, back to the story...

When it comes to providing a warning label to someone in a form, I usually utilize a "one shot" process.  You have one shot to get it right and then I will show you errors.

 

So, how to do that is, in the action that performs the OnSubmit for the form, the formula would be similar to the following:

UpdateContext({lclOneShot: formName.Valid});
If(formName.Valid, SubmitForm(formName))

Then, in the Visible of the warning label (for strictly entry of 10 digits only):

lclOneShot &&
!IsBlank(DataCardValue5.Text) &&
DataCardValue5.Visible &&
!IsMatch(DataCardValue5.Text,"^\d{10}$") 

And for formatting allowed entry (I will be using the formatting allowed option from here on in this reponse):

lclOneShot &&
!IsBlank(DataCardValue5.Text) &&
DataCardValue5.Visible &&
!IsMatch(DataCardValue5.Text, "^\(*\d{3}\)*-* *\d{3}-*\d{4}$")

 

That will govern the visibility of the warning label, which should just notify that the phone number is not valid.

What that will do is, if the user has tried to submit the form once and it is not valid (more on that shortly) AND the text entry is not blank (meaning that they started typing something) AND the text entry is Visible (assuming you have that governed by the dropdown to select changing the number) AND the data entered into the textinput does not match the pattern, then the warning label will be visible.

 

Now...the form have a really nice property on it called Valid.  Valid is true if all of the required fields have data entered into them.  That is really all it validates.  To "custom" validate, you need to do a little more on your own.

 

So...first we need to set the Required property of the datacard for that phone number field.  To do that, the formula on the Required property would be:

!IsBlank(DataCardValue5.Text) &&
DataCardValue5.Visible

This will make the field "required" (and thus included in the .Valid property of the form) only if the text input control is visible (again, assumed governed by your dropdown) AND there is something typed into that control.  If it is visible and there is nothing typed into the text input (remember, you said this is valid...they can say they want to change, but then not enter anything) then the field is not considered required.  But, if they do type something in, then it now needs to be correct.

 

The next thing we need to do it to establish the Update property of the data card.  The update property will not only determine what is written to the list when submitted, but also will participate in the .Valid property evaluation of the form.

So, the Update property would be:

If(DataCardValue5.Visible &&
   IsMatch(DataCardValue5.Text, "^\(*\d{3}\)*-* *\d{3}-*\d{4}$"),
   With({_l:Concat(Split(DataCardValue5.Text, ""), If(IsNumeric(Result), Result, ""))}, If(Len(_l)=10, _l, Blank())
   ),
   Self.Default
)

 

This should give all the formulas needed to have the .Valid work properly and also to abide by the rules of the change.  Also will provide a one shot opportunity for the user to enter a number without getting a warning.

 

There is some question in my mind on the Update formula only because we have not discussed some other "what if's" - like, what if the record already has a number and they choose to change and then enter nothing.  And a couple other What If's like that.  But, this should get you heading in the right direction.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi @RandyHayes 

 

Thank you yet again for getting back to me and for spending so much time on this just to help me.  I changed the column type to single line text.

 

Small aside - I also appreciate your input about the context of phone numbers. We will only require 10 digit numbers for this particular form because that number will always be a mobile number in the US (they will be receiving a text with a link to the number they provide ultimately).

 

So back to the main event, your instructions are beautiful, it is possible I just botched them up in execution. I will try to show my work to the teacher... 

 

On Submit for the form:

ElizabethK_0-1643313866915.png

 

Warning Label:

ElizabethK_1-1643313966919.png

 

Here is where I got confused and had to use google (shame). I didn't know what you meant by "formatting allowed entry" so what I found with google on where to put the format formula your provided was the "On Change" for DataCardValue5 - I could be wrong.

Formatting Allowed Entry (OnChange?)

ElizabethK_2-1643314146826.png

 

Okay so then I went to the dropdown question, the one that guides the visibility of the new phone number datacardvalue5, I changed that required formula

Required

 

ElizabethK_4-1643314353153.png

 

Then I did the update property of the New Phone card

Update

ElizabethK_5-1643314453098.png

 

So now if I put in a number that is NOT 10 digits...it gives me a warning but I still can submit it. - for example 2222. If I put one in that is in the XXX-XXX-XXXX format, it appears in the SharePoint data as 10 digits without dashes (perfect). If for some reason I make a wild entry and I type in 5$%#12 or something - it gives me the warning, but I can still submit the form and then nothing shows up in the SharePoint at all.

 

My guidance to you may have impacted this and after executing the formulas, it is possible I have changed my mind. Is there a way to make it required for them that if they are going to say yes there is a new number, they need to at least write out a 10 digit number? If not or if the effort of explaining how to accomplish that is too much, please let me know because I have taken a lot of your time. 

 

Otherwise it works very well and I am so thankful for your help. ❤️

 

 

 

 

@ElizabethK 

Ah my student 😊 where you went off the rail was in the third step - those formulas I provided were for the Visible property of your label.

In your second screen shot - that formula is correct if you are only going to allow users to enter 10 digits with no formatting in it.

The second formula (the one mentioned in my response as And for formatting allowed entry (I will be using the formatting allowed option from here on in this response):

That also was for the Visible property, but that formula would allow users to not only just enter 10 digits, but also, if they wanted to, to enter formatting characters.

You definitely do NOT want that on an OnChange action.

 

Let's fix that first and the look at the other scenario.  If they enter something that is not valid, then it should not let them submit.  So your wild entry should not have submitted.  And, it kind of does not submit that.

The way the formula was set up, if the entry was not valid, then it would have the existing phone number submitted.  This is why I mentioned the "There is some question in my mind on the Update formula only because we have not discussed some other "what if's"..."

Because, if a record has a phone number and a person chooses to enter a new one, but then does not add a valid number, it is really submitting the previous valid number and not the entered invalid number.

 

That can use some refinement I am sure, but since the "what if's" were a little murky in my mind for what you wanted, I took one route.  We can clean that up.  But for now, let's get the other issue fixed and see where things are.

 

Always happy to help 😁

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi friend/teacher/great one,

Working later tonight - did not have time to solve this during the day but I so appreciate your response. So, the app is working lovely, and works well enough for them to do UAT this weekend. The only thing is it isn't behaving consistently. So when I first go to the app and fill out the information - if I use a special character, it won't submit, but it also won't tell me with the warning label or with the error message that I have formatted for the form for OnFailure. After I submit a version that the form "likes" it will accept the phone number and put it in the sharepoint without dashes. Then on the reset version of the form (after I have submitted a form and get a new, reset screen), if I type in wild symbols, I get the warning label. I am not really sure where I went wrong at this point. I appreciate your help and I sent coffee yesterday. Have a wonderful weekend.

B7E520A8-A7F7-4451-B34C-EF950A313BC3.GIF

 

Uthhra
Post Prodigy
Post Prodigy

Hi,

In my case I have a number field which allows + and - symbol to enter in the field and gives a error message "The value - cannot be converted to a number". For other special
characters it's not allowed to enter.
Any help would be greatly appreciated.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages