Skip to main content

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

AttributeTypeDescription
messagestring = ngettext_lazy(...)The error message used when the validation fails, supporting pluralization based on the required minimum length.
codestring = min_lengthThe 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

NameTypeDescription
aintThe actual length of the value being validated.
bintThe minimum required length threshold defined for the validator.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
xSizedThe input value (such as a string or list) whose length needs to be measured.

Returns

TypeDescription
intThe integer length of the input value.