Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Numeric Range Boundary Assertion
Assert that a numeric parameter falls within inclusive lower and upper bounds.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Validation & Errors). Copy the parameterized template or run the self-contained example.
- 1Category: Validation & Errors
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
to validateRange value minVal maxVal fieldName
if value is less than minVal
say "Validation error:" fieldName "is below minimum" minVal
return false
.
if value is greater than maxVal
say "Validation error:" fieldName "exceeds maximum" maxVal
return false
.
return true
.
to validateRange value minVal maxVal fieldName
if value is less than minVal
say "Validation error:" fieldName "is below minimum" minVal
return false
.
if value is greater than maxVal
say "Validation error:" fieldName "exceeds maximum" maxVal
return false
.
return true
.
validAge is validateRange 28 18 65 "age"
overAge is validateRange 90 18 65 "age"
if validAge is not true
fail with "validateRange rejected valid age 28"
.
if overAge is not false
fail with "validateRange accepted out-of-bounds age 90"
.
say "Numeric range checks passed."
Installation & Usage
otter snippet inspect val-numeric-range
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.