📜  javascript 电话号码掩码 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:15.031000             🧑  作者: Mango

代码示例1
// JAVASCRIPT
document.getElementById('phone').addEventListener('input', function (e) {
  var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
  e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
});

// HTML