Ticket #1466: zip.diff
File zip.diff, 3.6 KB (added by , 18 years ago) |
---|
-
django/db/models/fields/__init__.py
689 689 def validate(self, field_data, all_data): 690 690 validators.isValidPhone(field_data, all_data) 691 691 692 class USZipCodeField(Field): 693 def get_manipulator_field_objs(self): 694 return [forms.USZipCodeField] 695 696 def validate(self, field_data, all_data): 697 validators.isValidUSZipCode(field_data, all_data) 698 692 699 class PositiveIntegerField(IntegerField): 693 700 def get_manipulator_field_objs(self): 694 701 return [forms.PositiveIntegerField] -
django/forms/__init__.py
937 937 except validators.ValidationError, e: 938 938 raise validators.CriticalValidationError, e.messages 939 939 940 class USZipCodeField(TextField): 941 "A convenience FormField for validating US Zip Codes (e.g. '12345 or 12345-1234')" 942 def __init__(self, field_name, is_required=False, validator_list=[]): 943 validator_list = [self.isValidUSZipCode] + validator_list 944 TextField.__init__(self, field_name, length=10, maxlength=10, 945 is_required=is_required, validator_list=validator_list) 946 947 def isValidUSZipCode(self, field_data, all_data): 948 try: 949 validators.isValidUSZipCode(field_data, all_data) 950 except validators.ValidationError, e: 951 raise validators.CriticalValidationError, e.messages 952 940 953 class USStateField(TextField): 941 954 "A convenience FormField for validating U.S. states (e.g. 'IL')" 942 955 def __init__(self, field_name, is_required=False, validator_list=None): -
django/core/validators.py
29 29 phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE) 30 30 slug_re = re.compile(r'^[-\w]+$') 31 31 url_re = re.compile(r'^https?://\S+$') 32 uszipcode_re = re.compile(r'^(\d{5}$)|(\d{5}-\d{4}$)') 32 33 33 34 lazy_inter = lazy(lambda a,b: str(a) % b, str) 34 35 … … 220 221 if field_data.upper() not in states: 221 222 raise ValidationError, gettext("Enter a valid U.S. state abbreviation.") 222 223 224 def isValidUSZipCode(field_data, all_data): 225 if not uszipcode_re.search(field_data): 226 raise ValidationError, gettext('Zip Codes must be in XXXXX or XXXXX-XXXX format. "%s" is invalid.') % field_data 227 223 228 def hasNoProfanities(field_data, all_data): 224 229 """ 225 230 Checks that the given string has no profanities in it. This does a simple -
docs/forms.txt
29 29 address = models.CharField(maxlength=100, blank=True) 30 30 city = models.CharField(maxlength=50, blank=True) 31 31 state = models.USStateField() 32 zip_code = models. CharField(maxlength=5, blank=True)32 zip_code = models.USZipCodeField() 33 33 place_type = models.IntegerField(choices=PLACE_TYPES) 34 34 35 35 class Admin: … … 518 518 * isWellFormedXmlFragment 519 519 * isExistingURL 520 520 * isValidUSState 521 * isValidUSZipCode 521 522 * hasNoProfanities 522 523 523 524 There are also a group of validators that are slightly more flexible. For