question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default Country Code?

See original GitHub issue

Is there a way append a default country code? If no Country code is typed? I am thinking along the lines of, mobile = PhoneNumberField(required=True, country='india') or mobile = PhoneNumberField(required=True, country='+91') My users are not smart enough to add their own country code, sometimes. It raises few errors. I currently tell them add the country code in a html placeholder.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
iuyoycommented, Jun 16, 2018

HI @CT83, I think you can add this config PHONENUMBER_DEFAULT_REGION = "IN" in settings.py.

2reactions
francoisfreitagcommented, May 15, 2020

Passing a region is not meant to restrict phone numbers to a given region, it is meant to interpret regional phone number input in the context of a specified region. It is not meant to force users to have a phone number in the given region.

For example, North American phone numbers are usually written 6044011234. That number only works for people calling from the North America, it is regional. To call it from another place in the world, one has to prefix it with +1, so that it reads +16044011234. In other regions in the world, 6044011234 may reach a different phone in that region. Setting the default region allows interpreting 6044011234 as +16044011234, uniquely identifying the phone number.

To implement your use case, you could create a validator that checks the phone number country code, e.g.:

>>> import phonenumber
>>> z = phonenumbers.parse('+33612345678')
>>> z.country_code
33  # France.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the default country code
Click Admin. Under Account Settings, click Organization Settings. Click the Settings tab. Under Default Country Code, select a country code. Click Save.
Read more >
How to Change Default Country Code For Phone Number ...
Make a tap on the list in the Phone number country code section. Now, select the country from the list and hit the...
Read more >
Gmail: How to Change the Default Country Code for Phone ...
In the General tab of the settings, the second section “Phone numbers” allows you to select a default country code. Select the country...
Read more >
Why does the country code default to +1 when I add a ...
Answer. The Support interface and Twilio backend design defaults the country code to US country code +1 if your phone number is nine...
Read more >
IBM-supplied country code defaults
Country/ region Country code Currency symbol Int. currency symbol Time picture string Da... Afghanistan AF X'9F404040' AFN HH:MI:SS YY... Albania AL Lek ALL HH:MI:SS YY... Algeria...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found