number
Creates a number schema.
const Schema = v.number<TMessage>(message);
Generics
TMessageextends ErrorMessage<NumberIssue> | undefined
Parameters
messageTMessage
Explanation
With number you can validate the data type of the input. If the input is not a number, you can use message to customize the error message.
Returns
SchemaNumberSchema<TMessage>
Examples
The following examples show how number can be used.
Integer schema
Schema to validate an integer.
const IntegerSchema = v.pipe(v.number(), v.integer());
Force minimum
Schema that forces a minimum number of 10.
const MinNumberSchema = v.pipe(v.number(), v.toMinValue(10));
Validate range
Schema that validates a number in a range.
const NumberRangeSchema = v.pipe(v.number(), v.minValue(10), v.maxValue(20));
Related
The following APIs can be combined with number.
Schemas
array, exactOptional, intersect, lazy, looseObject, looseTuple, map, nonNullable, nonNullish, nonOptional, nullable, nullish, object, objectWithRest, optional, record, set, strictObject, strictTuple, tuple, tupleWithRest, undefinedable, union
Methods
assert, config, fallback, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser
Actions
check, brand, description, finite, flavor, gtValue, guard, integer, ltValue, maxValue, metadata, minValue, multipleOf, notValue, notValues, rawCheck, rawTransform, readonly, safeInteger, title, toBoolean, toDate, toBigint, toMaxValue, toMinValue, toString, transform, value, values
Utils
entriesFromList, isOfKind, isOfType
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/number/