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
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (1,716)