Filtering textfield input on iOS
Hi,
I need to ask people to enter a 6-digit number (an integer) in a textfield, with only characters ranging from 0 to 9.
I use a regular TextField, with a DECIMAL type soft keyboard. On the CHANGE event, I check the contents of the TextField, and if I detect a non-digit character, I remove it from the TextField.text string, then re-assign the cleaned-up string to the TextField. On Windows, it works perfectly fine.
But on iOS, I get a weird behavior. If I type a comma (which is present on the decimal soft keyboard on iOS), my code tries to clean the TextField string, and when I assign it back to the TextField, the comma is still there, and the text of the TextField is fully selected (as if I had made a long press on the text, and selected it all). So there is a double issue: the cleaned-up string is not reassigned properly to the TextField content, and all the content of the TextField is selected, so the next key press on the soft keyboard will erase everything.
Do you know if there is some way to filter the contents of a TextField on iOS while you are typing, to limit the range of characters you can enter?
Thank you very much!
