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 }

 

posted on 2018-05-10 10:58  道法自然-法力无边  阅读(1594)  评论(0编辑  收藏  举报

导航