前言:uniapp input之输入手机号需要进行间隔显示。即18800188001显示成188 0018 8001。
部分代码如下:
// 间隔函数
formatPhone(val) { if (val) { if (this.inputPhoneValue.replace(/\s/g, "").length == 11 || this.inputPhoneValue.replace(/\s/g, "").length > 11) { console.log(val+" == 进来了: "+this.inputPhoneValue.replace(/\s/g, "").length) let a = val.substring(0,12); return a; } const matches = /^(\d{3})(\d{4})(\d{4})$/.exec(val); if (matches) { return matches[1] + " " + matches[2] + " " + matches[3]; } } return val; }, // 监听输入手机号 onInputPhone(e) { this.inputPhoneValue = this.formatPhone(e.detail.value); // 有值时显示清除按钮 },
标签:return,14,val,matches,replace,length,inputPhoneValue,2023,04 From: https://www.cnblogs.com/iuniko/p/17319841.html