bootstack.validation.ValidationRule#

class bootstack.validation.ValidationRule(rule_type, message='', **kwargs)#

Bases: object

A single validation rule that can be applied to a string value.

Supports the built-in rule types 'required', 'email', 'stringLength', 'pattern', 'compare', and 'custom', and carries a trigger policy that controls when the rule is evaluated.

type#

The validation rule type.

Type:

RuleType

message#

Custom error message; if empty a default is generated.

Type:

str

trigger#

When the rule fires — 'always', 'key', 'blur', or 'manual'.

Type:

RuleTriggerType

params#

Additional parameters specific to the rule type (e.g., min/max for 'stringLength', pattern for 'pattern', other_field for 'compare', func for 'custom').

Type:

dict

validate(value)#

Apply this rule to a value and return the result.

Parameters:

value (str) – The string value to validate.

Returns:

A ValidationResult with is_valid=True on success or is_valid=False with an error message on failure.

A 'custom' rule whose func raises is reported invalid rather than allowed to propagate. Its message is “Could not check this value (expected: …)”, carrying the rule’s own message as an expectation rather than as a verdict; a rule with no message reports UNCHECKABLE_MESSAGE.

Return type:

ValidationResult