Spec-Zone.ru › Valibot

number

Creates a number schema.

const Schema = v.number<TMessage>(message);

Generics

  • TMessage extends ErrorMessage<NumberIssue> | undefined

Parameters

  • message TMessage

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

  • Schema NumberSchema<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/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API