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?

 

 

13 REPLIES 13
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 Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,361)