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.

Return type:

ValidationResult