I feel that the problem of the question should be solved like this. Although Chinese characters may occupy 3 characters, we "think" it is two characters. The purpose is to control the length of Chinese and English nicknames, not for the length of utf8 So we should judge if ( a > ; 0x4e00 && a < 0x9fff){Then it’s Chinese, counting two characters} But it’s not so laborious at the moment, just limit it to a unified value, for example, 10 is good
First of all, a Chinese character does not necessarily occupy 2 bytes.
Secondly, you can try to control the length through
String().utf8.count
.Finally, you can also control it through regular expressions.
I have seen many input boxes that are counted in bytes.
I feel that the problem of the question should be solved like this. Although Chinese characters may occupy 3 characters, we "think" it is two characters. The purpose is to control the length of Chinese and English nicknames, not for the length of utf8
So we should judge if ( a > ; 0x4e00 && a < 0x9fff){Then it’s Chinese, counting two characters}
But it’s not so laborious at the moment, just limit it to a unified value, for example, 10 is good