判断字符串是否包含中文,过滤字符串中是否是整数或小数
1、判断字符串是否包含中文
/**
* 判断字符串是是否包含中文
* true包含中文,false不包含中文
* @param str
* @return
*/
public static boolean isContainChinese(String str) {
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(str);
if (m.find()) {
//包含中文
return true;
}
return false;
}
2、过滤字符串中是否是整数或小数:
/**
* 过滤字符串是整数或者是小数
* @param str
* @return
*/
public static boolean isNumeric(String str) {
if (str == null) {
return false;
}
return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
}
还没有评论,来说两句吧...