Schemas
Number

Number

Validate numeric values with optional coercion, integer/float checks, and range constraints.

Parameters

  • options?: table
    • required_error?: string
      • Custom required message
    • type_error?: string
      • Custom invalid type message
local amount = calid:number({
    required_error = "Amount is required",
    type_error = "Amount must be a number"
})

Options

  • :default(value) – Specifies a fallback value when the input is nil. Useful for optional fields with defaults.
  • :optional() – Allows nil as a valid value without causing a validation error.
  • :coerce() – Attempts to convert strings or other types into a number before applying further checks.
  • :int() – Asserts that a number is an integer; fails if it has a fractional component.
  • :float() – Ensures the number is a floating-point (allows decimals).
  • :positive() – Checks that the number is greater than zero.
  • :negative() - Checks that the number is less than zero (negative).
  • :min(n) – Enforces lower bounds on the value.
  • :max(n) – Enforces upper bounds on the value.
  • :multipleOf(n) – Validates that the number is an exact multiple of n.