这个功能可能在输入昵称校验的时候比较常用
public boolean isContainChinese(String str){
Pattern p = Pattern.compile("[\u4E00-\u9FA5|\\!|\\,|\\。|\\(|\\)|\\《|\\》|\\“|\\”|\\?|\\:|\\;|\\【|\\】]");
Matcher m = p.matcher(str);
if (m.find()) {
return true;
}
return false;
}
public int String_length(String nickName) {
int valueLength = 0;
String chinese = "[\u4E00-\u9FA5|\\!|\\,|\\。|\\(|\\)|\\《|\\》|\\“|\\”|\\?|\\:|\\;|\\【|\\】]";
for (int i = 0; i < nickName.length(); i++) {
String temp = nickName.substring(i, i + 1);
if (temp.matches(chinese)) {
valueLength += 2;
} else {
valueLength += 1;
}
}
return valueLength;
}