1. 代码
haveEmoji = (str) => {
//1.正则 2.emoji-regex库
let emojiReg = /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/gi;
const mm = emojiReg.test(str);
if (mm) {
Taro.showToast({
title: '不能输入emoji!',
icon: 'none',
duration: 2000,
})
}
const strResult = str.replace(emojiReg, "")
return strResult;
}
console.log(this.haveEmoji('测试'));//返回 测试
2. 测试emoji
emoji图标:[http://www.fhdq.net/emoji/emojifuhao.html]
3. emoji-regex库
https://www.npmjs.com/package/emoji-regex