输入框手机号分割
const ipt = document.querySelector('#ipt')
ipt.oninput = (e) => {
const v = (e.target.value + '').replace(/\D/g, '')
const r = v.replace(/^(\d{3})/, '$1-').replace(/(\d{4})/, '$1-').replace(/-$/, '')
ipt.value = r.substr(0, 13)
}
文章仅代表个人观点,如有任何疑问或疏漏之处,欢迎随时评论留言。