VeryApt / django-phone-field

Lightweight model and form field for phone numbers in Django
GNU General Public License v3.0
52 stars 13 forks source link

How can I access to the area code form my defined phoneField? #16

Closed agustin-jimenez closed 3 years ago

agustin-jimenez commented 3 years ago

Hi! I want some help. I need getting the area code from a defined PhoneField() on my model. Is it possible?

va-andrew commented 3 years ago

I would look at PhoneNumber.cleaned, which will give you a number expressed as +13335556666. From there, you can take characters 2-4 to extract the area code part -> my_number.cleaned[2:5].

agustin-jimenez commented 3 years ago

Thank you a lot!