Android EdText编辑框禁止输入表情符号(使用正则表达式)
使用正则表达式psfsNOT_EMOJI=“[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]”
找了好多个正则表达式,这个还是可以的
代码:返回true代表输入了表情,否则不是表情
publicstaticbooleanisEmote(Stringcontent){ Patternpattern=Pattern.compile(NOT_EMOJI); Matchermatcher=pattern.matcher(content); returnmatcher.find(); }
EdText控件监听
text.addTextChangedListener(newTextWatcher(){ @Override publicvoidbeforeTextChanged(CharSequences,intstart,intcount,intafter){ } @Override publicvoidonTextChanged(CharSequences,intstart,intbefore,intcount){ } //可以在这个方法里面操作完成 @Override publicvoidafterTextChanged(Editables){ //如果为true if(isEmote(s.toString())){ //删除输入的表情,开始位置和结束位置,表情符号长度为2个,所以减2 s.delete(s.length()-2,s.length()); }else{ textView.setText("("+s.length()+"/"+"200"+")"); } } });
以上所述是小编给大家介绍的AndroidEdText编辑框禁止输入表情符号(使用正则表达式),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!