问题
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