Ticket #3989: email_re.2.diff
File email_re.2.diff, 4.4 KB (added by , 18 years ago) |
---|
-
django/core/validators.py
21 21 ansi_date_re = re.compile('^%s$' % _datere) 22 22 ansi_time_re = re.compile('^%s$' % _timere) 23 23 ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere)) 24 25 ADDR_SPEC = """ 26 ((?: 27 [-!#$%&'*+/=?^_`{}|~0-9A-Z]+(?:\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)* # dot-atom 28 )|(?: 29 "(?:[\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*" # quoted-string 30 ))@( 31 (?:[A-Z0-9-]+\.)+[A-Z]{2,6} #domain 32 ) 33 """ 34 24 35 email_re = re.compile( 25 r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom 26 r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string 27 r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain 36 "^(?:" + ADDR_SPEC + ")|(?:\w[\w ]*)<" + ADDR_SPEC + ">$", re.VERBOSE | re.IGNORECASE) 37 28 38 integer_re = re.compile(r'^-?\d+$') 29 39 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}$') 30 40 phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE) … … 141 151 date(year, month, day) 142 152 except ValueError, e: 143 153 msg = gettext('Invalid date: %s') % gettext(str(e)) 144 raise ValidationError, msg 154 raise ValidationError, msg 145 155 146 156 def isValidANSIDate(field_data, all_data): 147 157 if not ansi_date_re.search(field_data): … … 244 254 raise ValidationError, _("The URL %s is a broken link.") % field_data 245 255 except: # urllib2.URLError, httplib.InvalidURL, etc. 246 256 raise ValidationError, _("The URL %s is a broken link.") % field_data 247 257 248 258 def isValidUSState(field_data, all_data): 249 259 "Checks that the given string is a valid two-letter U.S. state abbreviation" 250 260 states = ['AA', 'AE', 'AK', 'AL', 'AP', 'AR', 'AS', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'FM', 'GA', 'GU', 'HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA', 'MA', 'MD', 'ME', 'MH', 'MI', 'MN', 'MO', 'MP', 'MS', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM', 'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'PR', 'PW', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VA', 'VI', 'VT', 'WA', 'WI', 'WV', 'WY'] … … 373 383 self.error_message = error_message 374 384 375 385 def __call__(self, field_data, all_data): 376 # Try to make the value numeric. If this fails, we assume another 386 # Try to make the value numeric. If this fails, we assume another 377 387 # validator will catch the problem. 378 388 try: 379 389 val = float(field_data) 380 390 except ValueError: 381 391 return 382 392 383 393 # Now validate 384 394 if self.lower and self.upper and (val < self.lower or val > self.upper): 385 395 raise ValidationError(self.error_message) -
django/newforms/fields.py
260 260 raise ValidationError(self.error_message) 261 261 return value 262 262 263 ADDR_SPEC = """ 264 ((?: 265 [-!#$%&'*+/=?^_`{}|~0-9A-Z]+(?:\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)* # dot-atom 266 )|(?: 267 "(?:[\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*" # quoted-string 268 ))@( 269 (?:[A-Z0-9-]+\.)+[A-Z]{2,6} #domain 270 ) 271 """ 272 263 273 email_re = re.compile( 264 r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom 265 r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string 266 r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain 274 "^(?:" + ADDR_SPEC + ")|(?:\w[\w ]*)<" + ADDR_SPEC + ">$", re.VERBOSE | re.IGNORECASE) 267 275 268 276 class EmailField(RegexField): 269 277 def __init__(self, max_length=None, min_length=None, *args, **kwargs): -
docs/model-api.txt
189 189 190 190 A ``CharField`` that checks that the value is a valid e-mail address. 191 191 This doesn't accept ``maxlength``; its ``maxlength`` is automatically set to 192 75. 192 75. In addition to the expected ``joe.bloggs@some.domain.com`` address format, 193 the field also accepts email addresses with display names, such as 194 ``Joe Bloggs <joe.bloggs@some.domain.com>``. 193 195 194 196 ``FileField`` 195 197 ~~~~~~~~~~~~~