cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ElizabethK
Helper II
Helper II

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@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!

View solution in original post

14 REPLIES 14
RandyHayes
Super User
Super User

@ElizabethK 

Change your pattern to: 

IsMatch(DataCardValue5.Text,"^\d{10}$") 

This will return true if there are no other characters other than 10 digits.

 

I hope this is helpful for you.

_____________________________________________________________________________________
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!

Hey Randy,

 

I am always thankful for your help.  Your suggestion was good but I do think that I am being mislead by the blog I am following in the first place. I attempted to attach a video for you to see what I was doing, but MP4s are not allowed so I will try to break it down and then add a little gif at the end.

 

The blog instructs: Add label (under datacard for phone number), set visible property to: 

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

 

Under the DisplayMode of your submit button enter this:

If(
 !lblWarning.Visible,
 DisplayMode.Edit,
 DisplayMode.Disabled
)

So forget all of that - if I do these steps but instead use the directions you provided me...it works, but I still can type a period technically and also it doesn't give me the error message I made the label for in the first place.

0B658FBA-8012-4559-9889-D1F1A78D4CC1.GIF

Thank you as always, @RandyHayes 

RandyHayes
Super User
Super User

@ElizabethK 

Yes, welcome to the world of misinformation in those PowerApps blogs and videos! 😫

 

For what you are trying to do, your Visible property on the warning label should be:

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

This will display the label if the value is not 10 digits.

If you want to only display it once the user starts to type something in, then change it to the following:

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

 

Your DisplayMode property for the submit button should be fine (although I would write it a little different as a ! (not) in this case, makes it a little backward in reading...correct, but not mentally easy). So, this would read a little better:

If(
 lblWarning.Visible,
 Disabled,
 Edit
)

 

Incidentally, the process (in regard to phone numbers) is to consider that a non-formatted, number-only phone number is more specific to your data storage and not to the human factor.  Humans in general, will want to see a formatted number as that makes more sense than 10 digits in a series.

SO, the concept is to provide formatting and allow formatting as much as possible and yet Always convert to digits and validate digits while ignoring formatting. This is a more user friendly and accurate way.

Obviously the choice is yours as the designer, but thought I would mention this.

Here is a little video example:

ElizabethK.gif

You can see the validity of the number is irrelevant to the formatting.  Users can do either that they like - as long as they provide a valid phone number...that is the end result. 

 

_____________________________________________________________________________________
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 

I've bought you coffee before - but this is just ridiculous. You are so helpful to me, truly, thank you.

 

So now the special character warning I have displays as soon as I start writing the phone number. I made the visible property of the "must be a number between 0-9" false because it showed up right over the special character label I made. The submit button never appears to disable...which is fine, I don't care really, I just can't have them submitting something with characters.

DED728ED-C59F-4EB3-8C08-8F0240A2FC3E.GIF

 

What I am trying to accomplish here is just to ensure that when they put in a phone number, there are no special characters. I have powerautomated the responses of this form to be E-Mailed to a BOT that is being worked on by an IT Team. I agreed to make the information intake portion of the equation but the IT's feedback for me is that they cannot have any special characters in the phone number or it will make the BOT not work. The video solution you provided is the most ideal but beyond my current ability. 

RandyHayes
Super User
Super User

@ElizabethK 

Well, I can say that I certainly appreciate the coffee 🙂 And I'm always happy to help!

 

So...here is what I would suggest (and I am going to assume that the Phone Number is required in your form).

 

Actually...before I go into it, I should really verify that - is the Phone Number a required field?

 

_____________________________________________________________________________________
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!

Good question. No phone is not required. The form inquires if they need to update the E-Mail (Yes or No dropdown) or Phone (Yes or No dropdown). Validations will make the "Enter E-Mail" or "Enter Phone" fields appear to provide that information based on the yes or no choice they choose from those two drop downs. If the user filling out the form only needs to update the E-Mail, we don't want them to be stopped by requiring phone - because of that, phone is not required. I have to log off for the day so no rush on this and truly thank you for your help. 

RandyHayes
Super User
Super User

@ElizabethK 

No problem...have a good evening and let me know tomorrow if the following statement is correct...

  IF they choose Yes in the dropdown to update the Phone Number - is it not then required?

There is a method to the madness of my question.  It has to do with the form, the Updates and the disabling of the button...all happy together!

 

Let me know when you get a chance.

_____________________________________________________________________________________
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!
ElizabethK
Helper II
Helper II

@RandyHayes Answering from my phone now because it’s just that exciting to me!  Your statement is correct, if they select yes, even then it not a requirement to fill out phone. The BOT team requested this field not be required. Unclear as to why. Thank you so much and depending on you time zone have a good afternoon, evening or night! 

RandyHayes
Super User
Super User

@ElizabethK 

I'm Eastern US...so past the end of work here, but just can't break away!

 

So, here is the logic we need to figure out then.  If the phone number is not required...even if they select the change to be Just the Phone number, then what would make it invalid?

If the user selects Yes and enters nothing...that is good.

If the user selects Yes and enters 1 digit...that is not good.

If the user selects Yes and enters 10 digits (let's say formatted or not)...that is good.

 

Let me know if that logic is correct.

_____________________________________________________________________________________
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!

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,569)