Skip to content

Instantly share code, notes, and snippets.

@NurElHuda
Created February 24, 2021 01:06
Show Gist options
  • Save NurElHuda/9e60a6bfa78e74ae5b6717dba3a6b4db to your computer and use it in GitHub Desktop.
Save NurElHuda/9e60a6bfa78e74ae5b6717dba3a6b4db to your computer and use it in GitHub Desktop.

Revisions

  1. NurElHuda created this gist Feb 24, 2021.
    13 changes: 13 additions & 0 deletions django_algerian_phone_field_utilities.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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,]
    )