重点是要加上^$,表示从开头到结尾按照表达式的匹配

function matchesPattern(str) {
  let reg = /^\d{3}\-\d{3}\-\d{4}$/
  return reg.test(str)
}