java用于判断是否为乱码

//判断字符串是否为乱码
protected 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)) {
                String str = "" + ch[i];
                if (!str.matches("[\u4e00-\u9fa5]+")) {
                    return true;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}



你可能感兴趣的:(java,tomcat)