Skip to content

Text validators

MustMatchRegex(regex, /, *, match_type='match', flags=0, err_msg=None, extra_msg_args=None)

Bases: Validator

Validates that the value matches the provided regular expression.

PARAMETER DESCRIPTION
regex

The regular expression to validate.

TYPE: str

match_type

The type of match to perform. Must be one of 'match', 'fullmatch', or 'search'.

TYPE: Literal['match', 'fullmatch', 'search'] DEFAULT: 'match'

flags

Optional regex flags to modify the regex behavior. If regex is a compiled Pattern, flags are ignored. See re module for available flags.

TYPE: int | RegexFlag DEFAULT: 0

err_msg

error message.

TYPE: Optional[str] DEFAULT: None

RAISES DESCRIPTION
ValueError

If the value does not match the regex pattern.