number

Creates a number schema.

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

Generics

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

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));

The following APIs can be combined with number.

Schemas

Methods

Actions

Utils

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller
  • GitHub profile picture of kazizi55

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of antfu
  • GitHub profile picture of Thanaen
  • GitHub profile picture of osdiab
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of F0rce
  • GitHub profile picture of Unique-Pixels
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of nickytonline
  • GitHub profile picture of KubaJastrz
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of dslatkin