How to get TextBox to only accept numbers?
See original GitHub issueI looked around for ages but couldn’t find anything on this. I tried setting up validation (which is also very undocumented), but still have issues with that.
My TextBox is supposed to only accept unsigned integers. I think there should be some easy property to set to TextBox to define what types of inputs it can accept. (Android has this)
I tried
public uint? AppId {
get => _appId;
set
{
if(!(value is uint?))
{
throw new DataValidationException("Invalid Steam App Id");
}
_appId = value;
}
}
which I got from #4845, but the problem is that the program still closes with System.ArgumentException: 'f is not a valid value for UInt32. (Parameter 'value')'
, since the property itself doesn’t accept strings.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
How do I make a textbox that only accepts numbers?
Simply adding something like myNumbericTextBox.RegexString = "^(\\d+|)$"; should suffice. Share. Share a ...
Read more >Help, how to Make textbox accept numbers only windows ...
It can only accept the input of numbers 0-9, backspace and decimal point. 8 stands for backspace, 48 stands for number 0, 57...
Read more >How to force Input field to enter numbers only using ...
Now forcing input field type=”text” to accept numeric values only by using Javascript or jQuery. You can also set type=”tel” attribute in the ......
Read more >How to allow only numbers inside a textbox in Winforms C# ...
If you want to create an input that only accepts number, the first thing that you need to think in is the NumericUpDown...
Read more >text box to only accept numbers
4. In case anyone is looking for a solution to the above question: you can use html/javascript snippet and add a class to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@SpyceTewan as mentioned above, you can use Converter or Behaviors.
Although I would be nice to have UWP InputScope alternative (possible values - link). With that this issue could be solved simply
<TextBox InputScrope="Number" />
But I believe this feature should be planned and introduced only with IME and mobile in mind @kekekeks.@StefanH-AT: have you managed to fully restrict input of invalid characters, like letters (eg: ‘a’ or ‘b’)?
I’m trying to allow only entering of numbers, and it seems like this should work, but for me it only works after the app is minimized + restored, forcing a redraw.
I’ve tried calling InvalidateVisual()/ other methods after KeyDown/ KeyUp/ ValueChanghed, but this doesn’t really fix it, so I was thinking maybe you have a work around for it?
In this gif below, see that I can enter letters, these are not cleared until I minimize and restore the app: