Ticket #17637: pattern_charfield.patch
File pattern_charfield.patch, 1.4 KB (added by , 13 years ago) |
---|
-
django/forms/fields.py
182 182 return result 183 183 184 184 class CharField(Field): 185 def __init__(self, max_length=None, min_length=None, *args, **kwargs): 186 self.max_length, self.min_length = max_length, min_length 185 # Supply the validation pattern as Regular Expression 186 def __init__(self, max_length=None, min_length=None,pattern=None, *args, **kwargs): 187 self.max_length, self.min_length, self.pattern = max_length, min_length, pattern 187 188 super(CharField, self).__init__(*args, **kwargs) 188 189 if min_length is not None: 189 190 self.validators.append(validators.MinLengthValidator(min_length)) 190 191 if max_length is not None: 191 192 self.validators.append(validators.MaxLengthValidator(max_length)) 192 193 193 194 def to_python(self, value): 194 195 "Returns a Unicode object." 195 196 if value in validators.EMPTY_VALUES: … … 201 202 if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): 202 203 # The HTML attribute is maxlength, not max_length. 203 204 attrs.update({'maxlength': str(self.max_length)}) 205 if self.pattern: 206 attrs.update({'pattern':str(self.pattern)}) 204 207 return attrs 205 208 206 209 class IntegerField(Field):