鴻飛

导航

 
除了汉字、英文、数字之外的数字,自动过滤
/**
 * 除了汉字、英文、数字之外的数字,自动过滤
 * @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("");
}
View Code
是否只包含汉字、数字或英文
/**
 * 是否只包含汉字、数字或英文
 * @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();
}
View Code

 




posted on 2016-08-02 17:58  鴻飛  阅读(124)  评论(0编辑  收藏  举报