--- a/web/lib/django/contrib/localflavor/ca/forms.py Wed May 19 17:43:59 2010 +0200
+++ b/web/lib/django/contrib/localflavor/ca/forms.py Tue May 25 02:43:45 2010 +0200
@@ -2,9 +2,10 @@
Canada-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
-from django.forms.util import smart_unicode
+from django.forms.fields import Field, RegexField, Select
+from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
@@ -12,13 +13,20 @@
sin_re = re.compile(r"^(\d{3})-(\d{3})-(\d{3})$")
class CAPostalCodeField(RegexField):
- """Canadian postal code field."""
+ """
+ Canadian postal code field.
+
+ Validates against known invalid characters: D, F, I, O, Q, U
+ Additionally the first character cannot be Z or W.
+ For more info see:
+ http://www.canadapost.ca/tools/pg/manual/PGaddress-e.asp#1402170
+ """
default_error_messages = {
'invalid': _(u'Enter a postal code in the format XXX XXX.'),
}
def __init__(self, *args, **kwargs):
- super(CAPostalCodeField, self).__init__(r'^[ABCEGHJKLMNPRSTVXYZ]\d[A-Z] \d[A-Z]\d$',
+ super(CAPostalCodeField, self).__init__(r'^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] \d[ABCEGHJKLMNPRSTVWXYZ]\d$',
max_length=None, min_length=None, *args, **kwargs)
class CAPhoneNumberField(Field):