Skip to main content

RegexField

This class provides a specialized character field that validates input against a specific regular expression. It supports both string-based patterns and compiled regular expression objects, automatically managing a regex validator to ensure data integrity. By default, the field disables whitespace stripping to preserve the exact formatting required by the pattern.

Attributes

AttributeTypeDescription
regexstring or compiled regular expression objectregex can be either a string or a compiled regular expression object.

Constructor

Signature

def RegexField(
regex: [Union](../../contrib/gis/db/models/functions/union.md?sid=django_contrib_gis_db_models_functions_union)[str, Pattern],
**kwargs: dict
) - > null

Parameters

NameTypeDescription
regex[Union](../../contrib/gis/db/models/functions/union.md?sid=django_contrib_gis_db_models_functions_union)[str, Pattern]A string or a compiled regular expression object used for validation.
**kwargsdictAdditional keyword arguments passed to the parent CharField constructor.