DEV Community

Mauro
Mauro

Posted on

Answer: How to validate phone number in django?

Set a field with "PhoneNumberField()" in "models.py":

# "models.py"
from django.db import models
from phonenumber_field.modelfields import PhoneNumberField

class MyModel(models.Model):
    phone = PhoneNumberField()

Then, assign the widget "PhoneNumberPrefixWidget()" to the field with an initial country code like initial='US' in a custom form and assign the custom form to the admin…

Top comments (0)