MinLengthValidator
This class provides validation logic to ensure that a given value meets a minimum length requirement. It calculates the length of the input and compares it against a specified limit, raising a localized error message if the value is too short.
Attributes
| Attribute | Type | Description |
|---|---|---|
| message | string = ngettext_lazy(...) | The error message used when the validation fails, supporting pluralization based on the required minimum length. |
| code | string = min_length | The specific identifier used to categorize the validation error, typically for programmatic lookup. |
Constructor
Signature
def MinLengthValidator()
Methods
compare()
@classmethod
def compare(
a: int,
b: int
) - > boolean
Compares the actual length against the minimum required threshold to determine if a validation error should be triggered.
Parameters
| Name | Type | Description |
|---|---|---|
| a | int | The actual length of the value being validated. |
| b | int | The minimum required length threshold defined for the validator. |
Returns
| Type | Description |
|---|---|
boolean | True if the actual length is less than the limit value, indicating a validation failure. |
clean()
@classmethod
def clean(
x: Sized
) - > int
Calculates the length of the provided input value to prepare it for comparison against the limit.
Parameters
| Name | Type | Description |
|---|---|---|
| x | Sized | The input value (such as a string or list) whose length needs to be measured. |
Returns
| Type | Description |
|---|---|
int | The integer length of the input value. |