Krish
Krish

Reputation: 29

I am using a phonenumbers module for validating phone numbers. It works well,however I just need the National number as output

import phonenumbers
ph_no = "918332 88 1992"
print(phonenumbers.parse(ph_no, "IN"))

Output:

Country Code: 91 National Number: 8332881992

Desired Output:

8332881992

I just need the phonenumber to return. Please help!

Upvotes: 1

Views: 337

Answers (2)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476503

You can access the .national_number attribute [GitHub] of the parsed phone number:

import phonenumbers

ph_no = "918332 88 1992"

print(phonenumbers.parse(ph_no, "IN").national_number)

Upvotes: 0

CDJB
CDJB

Reputation: 14486

You need the national_number attribute of the parsed phone number. Docs can be found here.

import phonenumbers
ph_no = "918332 88 1992"
p = phonenumbers.parse(ph_no, "IN")
print(p.national_number)

Upvotes: 1

Related Questions