📜  用于格式化电话号码的 javascript 函数 - Javascript 代码示例

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

代码示例1
function formatPhoneNumber(phoneNumberString) {
  var cleaned = ('' + phoneNumberString).replace(/\D/g, '')
  var match = cleaned.match(/^(\d{3})(\d{3})(\d{4})$/)
  if (match) {
    return '(' + match[1] + ') ' + match[2] + '-' + match[3]
  }
  return null
}