1.定义一个公共的js文件 commonMethod.js
/** 替换emoji表情 */
function filterEmoji(name){
var str = name.replace(/[\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/ig, “”);
return str;
}
/** 替换空格键2 */
function filterSpace(name){
var str = name..replace(/\s+/g, ”);
return str;
}
module.exports = {
filterEmoji: filterEmoji,
filterSpace:filterSpace
}
2.在所需要的文件中使用
wxml文件
js文件
var commonMethod = require(“../../utils/commonMethod.js”); //根据自己的项目做出修改
nameInput: function (e) {
var that = this;
var str = commonMethod.filterEmoji(e.detail.value);
that.setData({
repairsDescribe: commonMethod.filterSpace(str);
})
},
简洁过滤
var userNick = e.detail.userInfo.nickName.replace(/\%uD.{3}/g, ”);
只要看正则过滤
评论前必须登录!
注册