问题描述
我正在尝试为这种格式的电话号码制作一个正则表达式模式:999-999-9999
I'm trying to make a regex pattern for phone numbers like this format : 999-999-9999
所以我尝试了这个表达式:
So I tried this expression :
\+\d(-\d{3}){2}-\d{4}
但格式适用于以下数字:+ 1-999-999-9999
But the format works on numbers like : +1-999-999-9999
如果有人帮我修改模式以使其与格式999-999-9999匹配,我将不胜感激,这意味着我不希望用户在字符串的第一个区域输入+号
I would appreciate if someone help me modifying the pattern to make it match the format 999-999-9999 , which means I don't want the user to enter the + sign at first of the string
谢谢
推荐答案
表达式 \ + \ d(-\d {3}){2} -\d {4}
您已尝试明确说:
The expression \+\d(-\d{3}){2}-\d{4}
you have tried explicitly says:
如果您不想要 +
和第一个数字,请不要在正则表达式中包含这些数字。
If you don't want the +
and the first single digit, don't include those in your regular expression.
此表达式 \d {3} -\d {3} -\d {4}
说:
这篇关于如何使用正则表达式验证器来获取电话号码,如999-999-9999的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!