HTML text input validation with localization

I have textboxes in an android app that should be limited to letters only (and maybe some enumerable basic character sets like "._-" etc.). My first instinct is to use Java's isLetter function. But I don't know if this localization is needed - my app needs to be localized in Japanese, among other languages, and the Android documentation does not provide hints as to how this might work (is isLetter dependent on the current language or all installed languages ​​or just a whitelist of Unicode characters). I know I cannot say that the Android keyboard does not allow emoji writing, so I can check the text string after entering it and accept it if it is ok, and reject it with an error if emoji characters (or others are detected).

Is there a generally accepted way to do this in Android?

+3


source to share


1 answer


isLetter should do what you want it to do. Here's an example:

public boolean isAlpha(String name) {
    char[] chars = name.toCharArray();

    for (char c : chars) {
        if(!Character.isLetter(c)) {
            return false;
        }
    }

    return true;
}

      

Also, Japanese characters are still characters, so they will still work. The way to do this has to do with encoding.



A string is just a sequence of characters (characters); the string itself has no encoding at all. Why is it worth replacing the symbols in the above with carrier pigeons. Same. Carrier pigeons have no coding. Also char doesn't exist.

From Check if a string contains only letters

and UTF-8 encoding; Only some Japanese characters are not converted

0


source







All Articles