7.3.3 Form Validation Techniques in Django

Ensuring correct user input is referred to as input validation. One of the major features of Django forms is the ability to customize validation, making is_valid() do exactly as the developer desires. Django provides two validation methods: validator and clean methods.

1. A validator is a simple regular expression to which Django matches a value. A validator is therefore a Boolean check: Does the value passed to the field match the regular expression?

2. A clean method is a function that takes as input some value, processes it, and is expected to return a new, cleaned value or else to raise a ValidationError exception if the value could not be cleaned.

Validators are associated with both model fields ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.