有人可以给我电话号码的正则表达式。它可以以XXX-XXX-XXXX或(XXX)-XXX-XXXX或XX-XXX-XXXX或XXXXXXXXX
的格式输入继承我所拥有的:
/\d{2,3}-\d{3}-\d{4}$/
答案 0 :(得分:1)
蛮力/易于维护/易于阅读/我认为就是你所拥有的。
(\d\d\d\-\d\d\d\-\d\d\d\d)|(\(\d\d\d\)\-\d\d\d\-\d\d\d\d)|(\d\d\-\d\d\d\-\d\d\d\d)|(\d\d\d\d\d\d\d\d\d)
或者如果您愿意:
(\d{3}\-\d{3}\-\d{4})|(\(\d{3})\-\d{3}\-\d{4})|(\d{2}-\d{3}\-\d{4})|(\d{9})
答案 1 :(得分:0)
((\d{2,3}|\(\d{3}\))-\d{3}-\d{4}|\d{9})
答案 2 :(得分:0)
大多数情况下,你关心的是数字:
/^([()-]*\d)[()-]*){9,10}$/.test(string);
or even
/^(\D*\d\D*){9,10}/.test(string);