index.js 299 B

123456789101112131415
  1. /**
  2. * 转换11位电话号码,给中间加上空格
  3. */
  4. export function formatTel (tel=''){
  5. tel = String(tel);
  6. if(tel.length!=11){
  7. return tel
  8. }else{
  9. const start = tel.substring(0,3)
  10. const inter = tel.substring(3,7)
  11. const end = tel.substring(7,11)
  12. return start+' '+inter+' '+end
  13. }
  14. }