cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jchicky
Level: Powered On

How can I restrict the range of values allowed in a text input box?

Similar to how the slider control allows me to configure a min and max value, how can I achieve the same with a text input box that is set to allow numbers? For example, I want to restrict the user to only enter a number from 0-100.
5 REPLIES 5
Sienna
Level 10

Re: How can I restrict the range of values allowed in a text input box?

Just set the textbox to format number and Maximum lenght to 3

text.png

Anonymous
Not applicable

Re: How can I restrict the range of values allowed in a text input box?

Thank you for the suggestion. I gave it a shot, but users are able to enter numbers from 101 to 999. I am hoping to cut them off at a specific number, such as 100 in my example.

Sienna
Level 10

Re: How can I restrict the range of values allowed in a text input box?

In that case try to add in OnChage property of your TextInput 

 

UpdateContext({restrict: Value(TextInput1.Text)}); If(restrict>100, UpdateContext({restrict: 100}))

 

And change Default property of the TextInput to

 

restrict

 

This will automaticaly change the value of that TextInput to 100 when user type value larger then 100. That is the only way you can do it

ChoiceDude
Level: Powered On

Re: How can I restrict the range of values allowed in a text input box?

I don't know if you already solved this issue, but I had this exact situation and I prevented the user from submitting the form if they entered a number into the text box (called Ans211) that was higher than 100:

 

  • On the "Submit" button, I had the following code on the OnSelect field:
    • If(Value(Text(Ans211)) > 100, " ", Submit(Form211); Navigate(...)
      • This disables the submit button unless the user has entered a number which is less than or equal to 100.
  • I also had a text box which read "Please enter a number between 1 and 100." which had the following code on the Visible field:
    • Value(Text(Ans211)) > 100

 

TL;DR: Use the Value and Text functions to extract the number that the user has entered (syntax: Value(Text(TextBox)) ) and use an If function to prevent the submit button from working unless the number is within your specified parameters. A pop-up warning is also easy and helpful to throw in there. 

Brian-Hamilton
Level: Powered On

Re: How can I restrict the range of values allowed in a text input box?

I had a similar problem. In my case, I had a Rich Text Editor box to which I wanted to add a character limit. Here's what I did.

 

Create a Rich Text Editor with the following properties:

BorderColor: If(Len(RichTextEditor.HtmlText)>1500, Color.Red, Color.Black)

 

Create a label with the following properties:

Text: "Label (" & 1500 - Len(RichTextEditor.HtmlText) & " character limit)"

Color: If(Len(RichTextEditor.HtmlText)>1500, Color.Red, Color.Black)

 

Create a button with the following properties:

On Select: If(Len(RichTextEditor.HtmlText)>1500, Notify("RichTextEditor exceeds 1500 character limit", NotificationType.Error), SubmitForm(Form))

 

There may be a more elegant way to achieve the same results, but this worked for me.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 73 members 4,141 guests
Please welcome our newest community members: