public boolean isMessyCode(String strName) {
try {
Pattern p = Pattern.compile("\\s*|\t*|\r*|\n*");
Matcher m = p.matcher(strName);
String after = m.replaceAll("");
String temp = after.replaceAll("\\p{P}", "");
char[] ch = temp.trim().toCharArray();
int length = (ch != null) ? ch.length : 0;
for (int i = 0; i < length; i++) {
char c = ch[i];
if (!Character.isLetterOrDigit(c)&&!"+".equals(c)) {
String str = "" + ch[i];
if (!str.matches("[\u4e00-\u9fa5]+")) {
return true;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
判断乱码问题
Character.isLetterOrDigit
该函数返回一个布尔值。如果字符是字母或数字,则布尔值为true,否则为false
str.matches("[\u4e00-\u9fa5]+")
判断字符串是否为中文