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
- required_error?:
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 isnil. Useful for optional fields with defaults.:optional()– Allowsnilas a valid value without causing a validation error.:coerce()– Attempts to convert strings or other types into anumberbefore 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 ofn.