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
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.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,504)