除了汉字、英文、数字之外的数字,自动过滤
/** * 除了汉字、英文、数字之外的数字,自动过滤 * @param str * @return * @throws PatternSyntaxException */ private String stringFilter(String str) throws PatternSyntaxException { String regEx = "[^\u4e00-\u9fa5^a-zA-Z^0-9]"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(str); return m.replaceAll(""); }
是否只包含汉字、数字或英文
/** * 是否只包含汉字、数字或英文 * @param str * @return * @throws PatternSyntaxException */ private boolean isValidate(String str) throws PatternSyntaxException { String regEx = "[\u4e00-\u9fa5a-zA-Z0-9]+"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(str); return m.matches(); }
原文:http://www.cnblogs.com/shixm/p/5730216.html