Skip to main content

validate_optional

Function validate_optional 

Source
pub fn validate_optional(
    rule: &ValidationRule,
    field_value: &str,
    field_name: &str,
    is_present: bool,
) -> Result<()>
Expand description

Validates a rule only if the field is present.

If the field is absent/null, validation is skipped (passes). If the field is present, the rule is applied normally.

§Arguments

  • rule - The validation rule to conditionally apply
  • field_value - The value being validated
  • field_name - Name of the field for error reporting
  • is_present - Whether the field is present/non-null

§Returns

  • Ok(()) if field is absent or if rule passes
  • Err if field is present and rule fails