android 判断内容中是否有(数字、emoji表情)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36636969/article/details/86526069

1.判断内容中是否有emoji表情

 /**
     * 是否包含表情
     *
     * @return
     */
    public static boolean containsEmoji(String source) {
        int len = source.length();
        for (int i = 0; i < len; i++) {
            char codePoint = source.charAt(i);
            if (!isEmojiCharacter(codePoint)) { // 如果不能匹配,则该字符是Emoji表情
                return true;
            }
        }
        return false;
    }

    private static boolean isEmojiCharacter(char codePoint) {
        return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD)
                || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD))
                || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF));

    }



 if (containsEmoji(content)) {
                Toast.makeText(MainActivity.this, "暂不支持表情输入",Toast.LENGTH_SHORT).show();
                return;
            }

2.判断是否包含数字

public boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }

猜你喜欢

转载自blog.csdn.net/qq_36636969/article/details/86526069