Canada localflavor: postal code validation too lax
|Reported by:||Paul Schreiber||Owned by:||Karen Tracey|
|Severity:||Keywords:||canada postal code|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In the Canada localflavor package, postal code validation is too lax. As of Django 1.1.1, we have this:
def __init__(self, *args, **kwargs): super(CAPostalCodeField, self).__init__(r'^[ABCEGHJKLMNPRSTVXYZ]\d[A-Z] \d[A-Z]\d$',
However, no postal code includes the letters D, F, I, O, Q, or U.
The letters W and Z are used, but are not currently used as the first letter.
I can't find this on the Canada Post web site, but it's documented in many places.
You want something like this:
def __init__(self, *args, **kwargs): super(CAPostalCodeField, self).__init__(r'^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] \d[ABCEGHJKLMNPRSTVWXYZ]\d$',