Regex for validating international phone numbers

Rated 4.81/5 based on 525 customer reviews

Something like @Andy Lester Maybe OP is trying to learn. )]* #Allow certain non numeric characters that may appear between the Area Code and the Exchange number.

Just because a problem has already been solved doesn't mean one should give up on the learning opportunity it presents.

Users get very frustrated if they are told their valid numbers are not acceptable.

According to E.164 international number can be 15 digits long and has no minimum length, other than the country code - at least one digit, and the subscriber number - at least one digit (shortest I've seen is three digits). The shortest one I've found so far was from NZ and was 5 digits long: 64010.

Since E.164 doesn't define minimum, personally, I would allow for a two digit-long international number just to be future proof. In several countries, mobile phone numbers are indistinguishable from landline phone numbers without at least a number plan lookup, and in some cases, even that won't help.

Since valid phone numbers consist only of digits, I doubt that rolling your own would risk missing some obscure case of at least. Your answer is misleading since the length of the number isn't necessary , you are specifying the number of groups that should match, the phone number itself can be 1 000 000 characters with the above regexp. Like I stated, the second (and third) are for if he/she changes his/her mind about a possible length requirement. Having opened this cookbook, you are probably eager to inject some of the ungainly strings of parentheses and question marks you find in its chapters right into your code.If you are ready to plug and play, be our guest: the practical regular expressions are listed and described in Chapters 4 through 9.

Leave a Reply