2

How can we use the python-phonenumbers library to determine whether a particular phone number is a mobile number or landline number?

Shamil Jamion
  • 183
  • 10

1 Answers1

4

Use phonenumbers.phonenumberutil.number_type to get the number type (after you have parsed the number). e.g.

x = phonenumbers.parse("0282784492", "AU")
phonenumbers.phonenumberutil.number_type(x)

So if you wanted to use x if it was not a fixed line number you could do:

if phonenumbers.phonenumberutil.number_type(x) is not phonenumbers.PhoneNumberType.FIXED_LINE:
    # Do something...

The possible phone number types are:

  • FIXED_LINE = 0
  • MOBILE = 1
  • FIXED_LINE_OR_MOBILE = 2
  • TOLL_FREE = 3
  • PREMIUM_RATE = 4
  • SHARED_COST = 5
  • VOIP = 6
  • PERSONAL_NUMBER = 7
  • PAGER = 8
  • UAN = 9
  • VOICEMAIL = 10
  • UNKNOWN = 99

See the full descriptions here.

Shamil Jamion
  • 183
  • 10