Check String whether it contains only Latin characters?

前端 未结 6 1940
感动是毒
感动是毒 2021-01-01 21:36

Greetings,

I am developing GWT application where user can enter his details in Japanese. But the \'userid\' and \'password\' should only contain English characters(L

6条回答
  •  轮回少年
    2021-01-01 21:56

    public static boolean isValidISOLatin1 (String s) {
        return Charset.forName("US-ASCII").newEncoder().canEncode(s);
    } // or "ISO-8859-1" for ISO Latin 1
    

    For reference, see the documentation on Charset.

提交回复
热议问题