1from django.core.validators import RegexValidator
2
3class PhoneModel(models.Model):
4 ...
5 phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
6 phone_number = models.CharField(validators=[phone_regex], max_length=17, blank=True) # validators should be a list
7
1# Custom field with international support and Android compatibility
2https://github.com/stefanfoulis/django-phonenumber-field