Browse Source

Written a regex to check given postal code.

Conflicts:
	coin/members/models.py
Hugo Lefeuvre 10 years ago
parent
commit
cf125cc11d
1 changed files with 7 additions and 3 deletions
  1. 7 3
      coin/members/models.py

+ 7 - 3
coin/members/models.py

@@ -9,7 +9,9 @@ from django.db.models.signals import pre_save
 from django.dispatch import receiver
 from django.contrib.auth.models import AbstractUser
 from django.conf import settings
+from django.core.validators import RegexValidator
 from ldapdb.models.fields import CharField, IntegerField, ListField
+
 from coin.offers.models import OfferSubscription
 from coin.mixins import CoinLdapSyncMixin
 from coin import utils
@@ -44,9 +46,11 @@ class Member(CoinLdapSyncMixin, AbstractUser):
                                            verbose_name=u'Téléphone mobile')
     # TODO: use a django module that provides an address model? (would
     # support more countries and address types)
-    address = models.TextField(verbose_name=u'Adresse', blank=True, null=True)
-    postal_code = models.CharField(max_length=15, blank=True, null=True,
-                                   verbose_name=u'Code postal')
+    address = models.TextField(verbose_name=u'adresse', blank=True, null=True)
+    postal_code = models.CharField(max_length=5, blank=True, null=True,
+                                   validators=[RegexValidator(regex=r'^\d{5}$',
+                                               message=u'Code postal non valide.')],
+                                   verbose_name=u'code postal')
     city = models.CharField(max_length=200, blank=True, null=True,
                             verbose_name=u'Commune')
     country = models.CharField(max_length=200, blank=True, null=True,