Ticket #2307: phone.patch
File phone.patch, 2.1 KB (added by , 18 years ago) |
---|
-
django/forms/__init__.py
891 891 SelectField.__init__(self, field_name, choices, 1, is_required, validator_list) 892 892 893 893 class PhoneNumberField(TextField): 894 "A convenience FormField for validating phone numbers (e.g. ' 630-555-1234')"894 "A convenience FormField for validating phone numbers (e.g. '(630) 555-1234')" 895 895 def __init__(self, field_name, is_required=False, validator_list=[]): 896 896 validator_list = [self.isValidPhone] + validator_list 897 TextField.__init__(self, field_name, length= 12, maxlength=12,897 TextField.__init__(self, field_name, length=20, maxlength=20, 898 898 is_required=is_required, validator_list=validator_list) 899 899 900 900 def isValidPhone(self, field_data, all_data): -
django/core/validators.py
23 23 email_re = re.compile(r'^[A-Z0-9._%-][+A-Z0-9._%-]*@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$', re.IGNORECASE) 24 24 integer_re = re.compile(r'^-?\d+$') 25 25 ip4_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$') 26 phone_re = re.compile(r'^ [A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE)26 phone_re = re.compile(r'^((1-)?[A-PR-Y0-9]{3}|\([A-PR-Y0-9]{3}\))[ -]?[A-PR-Y0-9]{3}[ -]?[A-PR-Y0-9]{4}$', re.IGNORECASE) 27 27 slug_re = re.compile(r'^[-\w]+$') 28 28 url_re = re.compile(r'^https?://\S+$') 29 29 … … 156 156 157 157 def isValidPhone(field_data, all_data): 158 158 if not phone_re.search(field_data): 159 raise ValidationError, gettext('Phone numbers must be in XXX-XXX-XXXX format. "%s" is invalid.') % field_data159 raise ValidationError, gettext('Phone numbers must be in XXX-XXX-XXXX or (XXX) XXX-XXXX formats. "%s" is invalid.') % field_data 160 160 161 161 def isValidQuicktimeVideoURL(field_data, all_data): 162 162 "Checks that the given URL is a video that can be played by QuickTime (qt, mpeg)"