hi there,
I’m using TextMesh Pro everywhere in my app,
I have an input field where users can type their names. Because the font I’ve selected does support only standard ASCII and some extended ASCII, I want to restrict the users from typing in letters that are non-ASCII.
My font asset has been exported with only ASCII characters. Also, this is the setup of my input field:
This works fine on iOS, I’m unable to change to my Cyrillic keyboard even though I have one.
On Mac, I cannot enter non-ASCII characters too.
But lots of Android users that come to our app obviously are able to specify non-ASCII characters, thus appearing ingame with names like “???”.
How is that possible? does the “Keyboard Type” actually restrict users from typing non-ASCII characters? Should I use a custom validator?
Thanks!
I’ll take a closer look but I would suggest you add your own validation as I would not be surprised if no validation was done based on keyboard type or even if that was consistent between devices.
Thanks for your input!
Are you aware of any problems on Android specifically on this matter?
@Stephan_B yes, confirmed, on Android with Cyrillic keyboard on, tried to type, no restriction, but in the text field rectangle characters appear. Then on server I get the unicode string.
P.S. In this sense I plan to try the following.
Somehow access the Glyph Info from script, so that I can get a list of the char codes of the characters present in the spritesheet. Then in the validator allow a character only if part of this list. Is there some easy approach to this?
Thanks
Look at the utility functions on the font asset like HasCharacter() and all the variants / overloads including one that will scan fallbacks as well. This will make it easy to know if a given or list of characters are available in the current font asset or any of its fallbacks.
@Stephan_B yes, indeed, this works great
I have an input field with onValidate assigned to a local function.
Interestingly, on iOS and in Editor on Mac it doesn’t get called at all.
However on Android it does get called, where I can restrict the characters.
P.S. is it possible to disable non-ASCII keyboard selection on Android, just like it is on iOS. Now users are able to switch to non-ASCII keyboard layouts
Thank you!