| 3330 | # UKPostcodeField ############################################################## |
| 3331 | |
| 3332 | UKPostcodeField validates that the data is a valid UK postcode. |
| 3333 | >>> from django.contrib.localflavor.uk.forms import UKPostcodeField |
| 3334 | >>> f = UKPostcodeField() |
| 3335 | >>> f.clean('BT32 4PX') |
| 3336 | u'BT32 4PX' |
| 3337 | >>> f.clean('GIR 0AA') |
| 3338 | u'GIR 0AA' |
| 3339 | >>> f.clean('BT324PX') |
| 3340 | Traceback (most recent call last): |
| 3341 | ... |
| 3342 | ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] |
| 3343 | >>> f.clean('1NV 4L1D') |
| 3344 | Traceback (most recent call last): |
| 3345 | ... |
| 3346 | ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] |
| 3347 | >>> f.clean(None) |
| 3348 | Traceback (most recent call last): |
| 3349 | ... |
| 3350 | ValidationError: [u'This field is required.'] |
| 3351 | >>> f.clean('') |
| 3352 | Traceback (most recent call last): |
| 3353 | ... |
| 3354 | ValidationError: [u'This field is required.'] |
| 3355 | |
| 3356 | >>> f = UKPostcodeField(required=False) |
| 3357 | >>> f.clean('BT32 4PX') |
| 3358 | u'BT32 4PX' |
| 3359 | >>> f.clean('GIR 0AA') |
| 3360 | u'GIR 0AA' |
| 3361 | >>> f.clean('1NV 4L1D') |
| 3362 | Traceback (most recent call last): |
| 3363 | ... |
| 3364 | ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] |
| 3365 | >>> f.clean('BT324PX') |
| 3366 | Traceback (most recent call last): |
| 3367 | ... |
| 3368 | ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] |
| 3369 | >>> f.clean(None) |
| 3370 | u'' |
| 3371 | >>> f.clean('') |
| 3372 | u'' |
| 3373 | |