RegexValidator
This class provides a mechanism to validate that a given input matches, or optionally does not match, a specified regular expression. It supports custom error messages, error codes, and regex flags to control matching behavior. The validator is designed to be used as a callable that raises a validation error when the input fails the defined criteria.
Attributes
| Attribute | Type | Description |
|---|---|---|
| regex | string | The regular expression pattern or compiled regex object used to validate the input value. |
| message | string = Enter a valid value. | The error message used in the ValidationError if the validation fails. |
| code | string = invalid | The error code used in the ValidationError if the validation fails. |
| inverse_match | boolean = false | Determines whether to invert the validation logic, raising an error if a match is found instead of when it is missing. |
| flags | integer = 0 | The regular expression flags used when compiling the regex string, such as re.IGNORECASE. |
Constructor
Signature
def RegexValidator(
regex: string|Pattern = None,
message: string = None,
code: string = None,
inverse_match: boolean = None,
flags: int = None
)
Parameters
| Name | Type | Description |
|---|---|---|
| regex | `string | Pattern` = None |
| message | string = None | The error message to raise on validation failure. |
| code | string = None | The error code to associate with the validation failure. |
| inverse_match | boolean = None | If True, validation fails if the regex matches; if False, validation fails if it does not match. |
| flags | int = None | Regular expression compilation flags. |