I have a Python FMX GUI App with an Edit
control that I want to only accept integer values with. In the past, I've done this kind of validation by overloading the KeyPress event and just removing characters that didn't fit the specification.
Is there a different way that is better? Maybe using regular expressions?
Ideally, this would behave such that pressing a non-numeric character would either produce no result or immediately provide the user with feedback about the invalid character.
The Edit
component in FMX has a FilerChar
property specifically for this purpose. So you could enter "0123456789" into the FilterChar
property and then only numbers are allowed in the Edit
.
So assuming you have an Edit
named "edtNumbers", you can simply write:
self.edtNumbers.FilterChar = "0123456789"