| 304 | Custom Validation and Cleaning: |
| 305 | ------------------------------- |
| 306 | |
| 307 | You can write custom validation methods. The method must be called |
| 308 | ``clean_FIELDNAME``. It is possible to alter the value, too. Example: |
| 309 | |
| 310 | >>> class OptionalPersonForm(Form): |
| 311 | ... first_name = CharField() |
| 312 | ... def clean_first_name(self): |
| 313 | ... value = self.fields["first_name"].widget.value_from_datadict(self.data, self.add_prefix("first_name")) |
| 314 | ... if not re.match(r'^[a-zA-Z]+$', value): |
| 315 | ... raise ValidationError("Only a-z A-Z allowed.") |
| 316 | ... return value |
| 317 | |
| 318 | |