Django Form Field to support US or international phone numbers?

I need a Django form field to support US or international phone numbers. Is there one? How can you verify the correctness of the phone number in the US or inside it.

+3
source share
3 answers

What about:

https://github.com/stefanfoulis/django-phonenumber-field

Explanation From the site:

An international phone number field for django that uses http://pypi.python.org/pypi/phonenumbers for verification.

from phonenumber_field.modelfields import PhoneNumberField
class MyModel(models.Model):
    name = models.CharField(max_length=255)
    phone_number = PhoneNumberField()
    fax_number = PhoneNumberField(null=True, blank=True)
+5
source

Lazerscience's answer is correct, but I want to give an alternative, since you also asked for international phone numbers.

Just use a RegexField with a regular expression for the format you need, for most types of phone numbers it can be easily google. In fact, many local taste fields are based on RegexField.

But use Local Flavor packages if they are suitable for all your needs!

+1
source

Source: https://habr.com/ru/post/1751583/


All Articles