[英]Phone Number Regex
I need a regular expression for phone number which includes country code, area code and phone number.The phone number format should be exactly like: 001-253-3478887
or 90-312-4900203
. 我需要电话号码的正则表达式,包括国家代码,区号和电话号码。电话号码格式应完全相同:
001-253-3478887
或90-312-4900203
。 I try this but it does not work. 我尝试了这个,但是没有用。 What should be the correct format?
什么是正确的格式? How can I get the phone number info?
如何获取电话号码信息?
(\(\d{3}-))?\d{3}-\d{4}
这将根据您提供的两个示例进行工作,
^\d{2,3}\-\d{3}-\d{7}$
^((\d-\d{3})|(\d{1,3}))\-\d{3}-\d{7}$
This regex will match all country codes. 此正则表达式将匹配所有国家/地区代码。 Country codes of 1 and 1-684 won't be valid in the other answers.
其他答案中的国家/地区代码1和1-684将无效。 It will also prevent country codes such as 1-42 from being allowed, since the only time there should be a separator in a country code is when it's four digits long.
这也将防止允许输入诸如1-42之类的国家/地区代码,因为国家/地区代码中唯一应该使用分隔符的时间是四位数长。 If you end up getting 4 digit country codes without the separator, use the following instead:
如果最终得到不带分隔符的4位国家/地区代码,请改用以下代码:
^((\d{4})|(\d{1,3}))\-\d{3}-\d{7}$
关于什么
\d{2,3}\-\d{3}\-\d{7}
您可以查看以下内容:
((\d{2,3}-))\d{3}-\d{7}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.