<commit_before>.. _ref-validators:

==========
Validators
==========

.. versionadded:: 1.2

Writing validators
==================

A validator is a callable that takes a value and raises a
``ValidationError`` if it doesn't meet some criteria. Validators can be useful
for re-using validation logic between different types of fields.

For example, here's a validator that only allows even numbers::<commit_msg>Added missing module directive for validators documentation.<commit_after>.. _ref-validators:

==========
Validators
==========

.. versionadded:: 1.2
.. module:: django.core.validators
    :synopsis: Validation utilities and base classes

Writing validators
==================

A validator is a callable that takes a value and raises a
``ValidationError`` if it doesn't meet some criteria. Validators can be useful
for re-using validation logic between different types of fields.

For example, here's a validator that only allows even numbers::
{'fraction_non_alphanumeric': 0.13926701570680627, 'fraction_numerical': 0.004188481675392671, 'mean_word_length': 5.089171974522293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3792048', 'n_tokens_mistral': 249, 'n_tokens_neox': 232, 'n_words': 111}