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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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