5

I'm trying to validate an international mobile number.

For example: "+972523254545".

Afaik, this number should be valid everywhere.

But this library requires "region" too. why is that and how can I overcome it?

Hagai L
  • 1,593
  • 1
  • 18
  • 40

1 Answers1

3

region should not be a required field. It is not used for phone numbers with a leading '+'. Without specifying a region I can parse that number in the python version:

>>> import phonenumbers

>>> phonenumbers.parse('+972523254545')
PhoneNumber(country_code=972, national_number=523254545, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=None, preferred_domestic_carrier_code=None)

And that number parses fine without specifying a region on their demo page.


If you really must speficy a region, then just stick any region in there. It's going to be ignored because the leading "+" in the number indicates that it's lead by an international calling code.

QuestionC
  • 10,006
  • 4
  • 26
  • 44