Numeric builder that stores a real number, not a string.
- Numeric helpers live directly on the builder:
positive(),nonNegative(),integer(),step() min()/max()set numeric bounds (not character length like on string builders)- Inherits base builder methods but not string builder methods
Number.tsxtsx
| 1 | const schema = { |
| 2 | quantity: field.number('Quantity') |
| 3 | .required() |
| 4 | .positive() |
| 5 | .integer() |
| 6 | .step(5, 'Order in increments of 5'), |
| 7 | } |
Defaults, inheritance & field methods
- defaultValue is
0 - type is
number - Shared methods: see Base field builder
- String-specific helpers do not apply here;
min()andmax()operate on real numeric values
Number-specific methods:
| Method | Type | Description |
|---|---|---|
min(value, message?) | value: number | Sets the minimum accepted numeric value. |
max(value, message?) | value: number | Sets the maximum accepted numeric value. |
positive(message?) | message?: string | Requires a value strictly greater than zero. |
nonNegative(message?) | message?: string | Requires a value greater than or equal to zero. |
integer(message?) | message?: string | Restricts the value to whole numbers only. |
gt(value, message?) | value: number | Strict greater-than check against a static number. |
gte(value, message?) | value: number | Greater-than-or-equal check against a static number (inclusive lower bound). |
lt(value, message?) | value: number | Strict less-than check against a static number. |
lte(value, message?) | value: number | Less-than-or-equal check against a static number (inclusive upper bound). |
between(min, max, message?) | min: number, max: number | Requires the value to fall inside [min, max] (both bounds inclusive). |
multipleOf(value, message?) | value: number | Requires the value to be an exact multiple of another number. Throws a helper message if called with value <= 0. |
greaterThan(valueOrRef, message?) | number | string | FieldReference | Cross-field version of gt(). Accepts another field name or a ref() path so you can enforce rules like maxPrice > minPrice. |
lowerThan(valueOrRef, message?) | number | string | FieldReference | Cross-field version of lt(). Accepts another field name or a ref() path, e.g. ref('maxQuantity'). |
step(stepValue, message?) | stepValue: number | Requires the value to be a clean multiple of the provided step. Thin alias over multipleOf() with a step-oriented default message. |
Recipes
Patterns that showcase number-specific strengths.
Batch order in increments
BatchQuantity.tsxtsx
| 1 | const schema = { |
| 2 | quantity: field.number('Quantity') |
| 3 | .required() |
| 4 | .integer() |
| 5 | .positive() |
| 6 | .step(5, 'Order in multiples of 5'), |
| 7 | } |
Percentage slider
Discount.tsxtsx
| 1 | const schema = { |
| 2 | discount: field.number('Discount %') |
| 3 | .min(0) |
| 4 | .max(100) |
| 5 | .nonNegative() |
| 6 | .defaultValue(0), |
| 7 | } |
Seat limit with business rule
Seats.tsxtsx
| 1 | const schema = { |
| 2 | seats: field.number('Seats') |
| 3 | .integer() |
| 4 | .positive() |
| 5 | .validate((value) => |
| 6 | value <= 500 |
| 7 | ? null |
| 8 | : 'Maximum 500 seats per workspace.', |
| 9 | ), |
| 10 | } |
Price with two-decimal step
UnitPrice.tsxtsx
| 1 | const schema = { |
| 2 | unitPrice: field.number('Unit price') |
| 3 | .nonNegative() |
| 4 | .step(0.01, 'Use two decimal places.'), |
| 5 | } |