cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AnthonyPhan
Level 8

Text input HH:mm formatting

Hi All,

 

I have a text input where users can input the total time spent on an activity. I would liek this input to only accept input in the format HH:mm. where:

 

1:30 is 1.5 hours

1:03 is  1.05 hours 

2      is 2 hours

2:00 is 2 hours

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
AnthonyPhan
Level 8

Re: Text input HH:mm formatting

Hi @Sienna,

I appreciate the suggestion, although your solution is practical I believe it would deduct from the user experience (due to two button presses).

 

The solution I came to was using a single standard text input and checking the format of the test input using the "IsMatch" function with Regex. I then proceed to split the string to extract the HH and mm components using a formular similat to the one below:

 

If(IsMatch(Timetest.Text,"^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$") , 
   UpdateContext({Debug: "Time detected hours:" & First(Split(Timetest.Text, ":")).Result & " Minutes:" & Last(Split(Timetest.Text, ":")).Result}),
   UpdateContext({Debug: "Invalid time input"})
)

 

View solution in original post

2 REPLIES 2
Sienna
Level 10

Re: Text input HH:mm formatting

The best way is to add two inputtexts. One for hours and one for minutes. Then conect it together or transfer it into a minutes or whatever is good for you
Highlighted
AnthonyPhan
Level 8

Re: Text input HH:mm formatting

Hi @Sienna,

I appreciate the suggestion, although your solution is practical I believe it would deduct from the user experience (due to two button presses).

 

The solution I came to was using a single standard text input and checking the format of the test input using the "IsMatch" function with Regex. I then proceed to split the string to extract the HH and mm components using a formular similat to the one below:

 

If(IsMatch(Timetest.Text,"^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$") , 
   UpdateContext({Debug: "Time detected hours:" & First(Split(Timetest.Text, ":")).Result & " Minutes:" & Last(Split(Timetest.Text, ":")).Result}),
   UpdateContext({Debug: "Invalid time input"})
)

 

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (4,634)