public static boolean isChinese(String str) {
for(int i=0; i<str.length(); i++) {
char ch = str.charAt(i);
if(ch < 0x4e00 || ch > 0x9fa5) {//汉字:[0x4e00,0x9fa5]
return false;
}
}
return true;
}
public static boolean isEnglish(String str) {//str.matches("^[a-zA-Z]*")
for(int i=0; i<str.length(); i++) {
char ch = str.charAt(i);
if((ch < 0x61 && ch > 0x5a) || ch < 0x41 || ch > 0x7a) {//小写字母:[0x61,0x7a];大写字母:[0x41,0x5a]
return false;
}
}
return true;
}
public static boolean isNumb(String str) {
if(str.matches("^[0-9]*")) {
return true;
} else {
return false;
}
}java判断字符串为中、英文
最新推荐文章于 2019-11-07 14:45:08 发布
本文提供了一个简单的Java方法,用于检查字符串是否仅包含汉字、英文字符或数字。通过正则表达式,实现对输入字符串的快速验证。
4668

被折叠的 条评论
为什么被折叠?



