cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frederico
Advocate I
Advocate I

How to autoformatting a textinput while the user is typing in it?

Hi power community,

 

Here is the problem:

 

I need to autoformat a textinput while the user is typing in it. It's not so simple as autoformatting currency because the field is a driver license number with the following pattern:

 

"[a-zA-Z]" & Digit & Digit & Digit & Digit & Hyphen & Digit & Digit & Digit & Digit & Digit & Hyphen & Digit & Digit & Digit & Digit & Digit

 

For example: A1234-12345-12345

 

Until now, I've managed to do something similar with the following approach (if the pattern is just numbers works fine):

 

Using 2 controls: Timer1 and TextInput1

 

TextInput1 properties:  default = var  /  Maximum length = 17

 

Timer1 properties: Duration= 2 / Repeat = on / OnTimerStart =  as the below image

 

Frederico_1-1628800223641.png

 

The problem with that approach is if I insert a letter won't work (probably because of the Value function). 

 

Do you know how I can solve this?

 

Thanks!

 

3 REPLIES 3

Thanks for sharing. I already knew these links, they help me to solve the problem for only numbers pattern.

 

But I don't know how to adapt to a pattern that contains a letter in the first place (e.g.: A1234-12345-12345)

WarrenBelz
Super User
Super User

HI @Frederico ,

This will do the job at the end of the input (of 14 characters) on the OnChange of the Text box

UpdateContext(
   {
      varText: Self.Text,
      varLen: Len(Self.Text)
   }
);
If(
   varLen >= 14,
   UpdateContext(
      {
         varText: 
         Left(
            varText,
            5
         ) & "-" & 
         Mid(
            varText,
            6,
            5
         ) & "-" & 
         Mid(
            varText,
            11,
            5
         ) 
      }
   );
   Reset(Self)
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

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.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (4,442)