Regex for phone number with country code [duplicate]

杀马特。学长 韩版系。学妹 提交于 2021-02-05 12:24:54

问题


I am trying to write regex for a phone number with a country code. The number is supposed to begin with a "+" sign. I tried and solved the first part for + sign.

^\+\d{12}$

The issue here is that it will only work for 12 digits long number starting with + . How can I make it work for any number of digits in range of <= 15 ?


回答1:


Just change {12} to + in your regex, so that it would match one or more digits. But why?

^\+\d+$

Update:

^\+\d{1,15}$



回答2:


^\+\d{5,12}$ for min 5 and max 12 digits

^\+\d{5,}$ for min 5 digits

^\+\d+$ for min 1 digit




回答3:


see this which is allow 10 to 15 digit only....

^\+\d{10,15}$


来源:https://stackoverflow.com/questions/31025958/regex-for-phone-number-with-country-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!