Validate phone number against 10 digits
This commit is contained in:
parent
7330e5353f
commit
1dab5e1c8a
2 changed files with 34 additions and 1 deletions
19
manuels/migrations/0011_auto_20180524_0013.py
Normal file
19
manuels/migrations/0011_auto_20180524_0013.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 2.0.5 on 2018-05-23 22:13
|
||||
|
||||
from django.db import migrations, models
|
||||
import manuels.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('manuels', '0010_remove_book_collection'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='teacher',
|
||||
name='phone_number',
|
||||
field=models.CharField(help_text="En cas d'urgence, 10 chiffres.", max_length=10, validators=[manuels.models.phone_validator], verbose_name='numéro de téléphone'),
|
||||
),
|
||||
]
|
|
@ -18,6 +18,15 @@ class BaseModel(models.Model):
|
|||
updated_at = models.DateTimeField('mis à jour le', auto_now=True)
|
||||
|
||||
|
||||
def phone_validator(value):
|
||||
regex = re.compile(r'^\d{10}$')
|
||||
if not regex.match(value):
|
||||
raise ValidationError(
|
||||
"%(value)s n'est pas un numéro de téléphone valide. Format attendu : 10 chiffres.",
|
||||
params={'value': value}
|
||||
)
|
||||
|
||||
|
||||
class Teacher(BaseModel):
|
||||
class Meta:
|
||||
verbose_name = 'enseignant'
|
||||
|
@ -25,7 +34,12 @@ class Teacher(BaseModel):
|
|||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
first_name = models.CharField('prénom', max_length=100)
|
||||
last_name = models.CharField('nom', max_length=100)
|
||||
phone_number = models.CharField('numéro de téléphone', help_text="En cas d'urgence", max_length=10)
|
||||
phone_number = models.CharField(
|
||||
'numéro de téléphone',
|
||||
help_text="En cas d'urgence, 10 chiffres.",
|
||||
max_length=10,
|
||||
validators=[phone_validator]
|
||||
)
|
||||
email = models.EmailField(
|
||||
'adresse email',
|
||||
help_text='Utilisée pour vous transmettre votre lien personnel',
|
||||
|
|
Loading…
Reference in a new issue