Created
February 24, 2021 01:06
-
-
Save NurElHuda/9e60a6bfa78e74ae5b6717dba3a6b4db to your computer and use it in GitHub Desktop.
Django Algerian phone field utilities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.validators import RegexValidator | |
from django.db import models | |
from django.utils.crypto import get_random_string | |
def get_random_phone(): | |
return '07'+ get_random_string(length=8, allowed_chars='123456789') | |
phone_pattern_validator = RegexValidator('(0|\+213|00213){1}([1-9]){1}([0-9]{8})', message='Invalid phone format') | |
phone = models.CharField( | |
max_length=16, unique=True, default=get_random_phone, blank=True, validators=[phone_pattern_validator,] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment