js来格式化手机号 如:*** **** **** 的格式

// 我这个是在微信小程序中使用的,其他地方也可以使用
handleNum: function (e) { // console.log(e.detail.cursor) let val = e.detail.value.replace(/[^d]/g, '') this.data.phoneNum = val let arr = val.split('') let str = '' arr.forEach(function(val, ind) { if (ind === 3 || ind === 7) { str += ' ' } str += val // (3 === arr || 7 === arr) && (str += ' ') // str += val }) console.log(this.data.phoneNum) return str }
原文地址:https://www.cnblogs.com/suntao666/p/9018527.html