Emoji表情、特殊字符过滤(支持输出中文,英文,- 横线、_下划线)
将不支持的字符替换为空串
😊爱吃大蒜_🇨🇳$£€♀﹉#©️*-*-
爱吃大蒜_--
public class EmojiExcludeFilter implements InputFilter {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
return filterNickName(source);
}
public String filterNickName(CharSequence source){
String speChat = "[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]|[^\u4e00-\u9fa5a-zA-Z0-9-_]";
Pattern pattern = Pattern.compile(speChat,Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(source.toString());
if (matcher.find()) {
return matcher.replaceAll("");
}
return null;
}
}
网友评论