validate phone number for iran
This commit is contained in:
parent
74677a3790
commit
34550be387
2 changed files with 16 additions and 2 deletions
|
|
@ -9,13 +9,14 @@ from django.contrib.auth.validators import UnicodeUsernameValidator
|
|||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework.exceptions import APIException
|
||||
import uuid
|
||||
|
||||
from .provinces_and_cities import state
|
||||
from .tasks import send_notification
|
||||
|
||||
from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS
|
||||
from .validators import PhoneNumberValidator
|
||||
|
||||
|
||||
class UserManager(BaseUserManager):
|
||||
use_in_migrations = True
|
||||
|
|
@ -106,7 +107,8 @@ class User(AbstractUser):
|
|||
blank=True,
|
||||
null=True
|
||||
)
|
||||
phone_number = models.CharField(_('phone number'), max_length=30, blank=True, null=True, unique=True)
|
||||
phone_number = models.CharField(_('phone number'), max_length=30, blank=True, null=True, unique=True,
|
||||
validators=[PhoneNumberValidator],)
|
||||
otp = models.CharField(_('otp'), max_length=6, blank=True, null=True)
|
||||
otp_expire = models.DateTimeField(_('otp expire'), blank=True, null=True)
|
||||
otp_try = models.IntegerField(_('otp try'), blank=True, null=True, default=0)
|
||||
|
|
|
|||
12
apps/users/validators.py
Normal file
12
apps/users/validators.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from django.core import validators
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
@deconstructible
|
||||
class PhoneNumberValidator(validators.RegexValidator):
|
||||
regex = r'^\+98\d{10,10}$'
|
||||
message = _(
|
||||
"Phone number must be entered in the format: '+989999999999'."
|
||||
)
|
||||
flags = 0
|
||||
Loading…
Add table
Reference in a new issue