cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Forcing Integer input for a Text Input Control

Hi,

 

I'm trying to force a Text Input control to accept only integers but it isn't working so far.

Right now I'm using the following code in the OnChange property of the Text Input control:

If(Value(TextInput.Text ) <> RoundDown(Value(TextInput.Text),0),
Set(resetTextBox, true));Set(resetTextBox, false)

The Reset property of this control is set to the resetTextBox variable.

 

Has anyone accomplished this in a different way?

 

 

11 REPLIES 11
timl
Super User III
Super User III

Hi @Anonymous 

Could you explain what it is about your code that doesn't work?

In the test that I carried out, the text input control accepts whole numbers. If the input value includes numbers after the decimal point, the text input control clears itself. Are you expecting some different behaviour?

yashag2255
Dual Super User II
Dual Super User II

Hi @Anonymous 

 

You can try to update the Format property of your TextInput to TextFormat.Number. It will only allow to enter the numbers.
MicrosoftTeams-image (73).png

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Hi @yashag2255 

I think the issue with the TextFormat.Number format is that it allows fractional numbers (eg 2.55). As I understand, @Anonymous wants to allow only whole Integer numbers.

yashag2255
Dual Super User II
Dual Super User II

Hi @timl , yes there is a limitation where it allows the decimal point but at the same time we can reset the control as soon as a non-number character is identified, user does not need to move out of the control to see the changes/ reset the textbox. And for removing the decimal value, I think the code @Eduardo_GzzC  used will suffice the requirement. 

 
 @Eduardo_GzzC are you getting any error? I tried out your code and it is resetting the text input control when the user clicks out somewhere else on the screen. But with TextFormat.Number, your input will reset as soon as a character is detected.
 
Thoughts?
Anonymous
Not applicable

Hi, thanks for the answers so far. The code is working after I click outside as expected. I just wanted something that prevents even typing the decimal point. Like when you choose a number as a format and it won't accept text.

 

I guess it would have to be like this for the moment until I find a workaround.

Hey @Anonymous 

 

Yes, this is not supported directly. This workaround will work until Microsoft releases more options for the Text Input controls.

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Craig60
Frequent Visitor

If(IsMatch(NumbersOnlyTextbox.Text,"\.",MatchOptions.Contains) = true, "No decimals allowed")

@Craig60Hello, I was wondering if the IsMatch formula could be put in the Format box.

Craig60
Frequent Visitor

Hi @CadelDev,  Looks like the Format box is currently limited to ‘Text’ or ‘Number’.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

PA Community Call

Power Apps Community Call

Next call is happening on April 21st at 8a PST.

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (41,141)