报错已经提示了`/`这个符号出的问题, 因为wsx不支持使用正则表达式字面量写法 wxs正则需要调方法: var telEncrypt = function(str){ // wxs页面调用 var talReg = getRegExp('^[1][3,4,5,7,8,9][0-9]{9}$') var length = str.length if (talReg.test(str)) { return str.substring(0, 3) + "****" + str.substring(length - 4, length) } else { return str } } var a = getRegExp("x", "img"); console.log("x" === a.source); console.log(true === a.global); console.log(true === a.ignoreCase); console.log(true === a.multiline); 官方文档 > > [https://developers.weixin.qq.com/miniprogram/dev/reference/wx...](https://link.segmentfault.com/?enc=5tUyqpLdT%2FGDaFIcb6%2F5Cw%3D%3D.zrsoAK%2BLEIG%2BNGlJogDaLG3eod01GFdKmP6M43yZfI6swMKu6k8yk6Nh5im3zDUGSm5fp4UeoZjDUeJkRxkzHefI9pptoZLpkx2gSyw889dQde1SDP9Mf5A5utSe9EjU)