我正在使用正则表达式来验证输入到 html 输入中的电话号码。我想要一个三位数、三位数、四位数的模式,用空格、破折号或点分隔。
333-333-3333 should match.
333.333.3333 should match.
333 333 3333 should match.
33 shouldn't match.
333/333/3333 shouldn't match
当我有
pattern="[0-9]{3}[\s.-][0-9]{3}[\s.-][0-9]{4}"
时,它会失败并接受我输入的任何内容。
当我拥有
pattern="[0-9]{3}(\s|.|-)[0-9]{3}(\s|.|-)[0-9]{4}"
时,它就会按照我的预期工作。
(\s|.|-)
不应给出与 [\s.-]
相同的结果