View Source Vx.Number (Vx v0.4.0)
The Integer type provides validators for integers.
Summary
Functions
Requires the number to be within the given range.
Requires the number to be greater than the given value.
Requires the number to be greater than or equal to the given value.
Requires the number to have no decimal places.
Requires the number to be less than the given value.
Requires the number to be less than or equal to the given value.
Requires the number to be negative.
Requires the number to be positive.
Requires the number to be in the given range.
Builds a new Number type.
Types
@type numeric() :: t() | Vx.Float.t() | Vx.Integer.t()
@opaque t()
The number type.
Functions
Requires the number to be within the given range.
Requires the number to be greater than the given value.
Requires the number to be greater than or equal to the given value.
@spec integer(schema) :: schema when schema: numeric()
Requires the number to have no decimal places.
Examples
iex> Vx.Number.integer() |> Vx.validate!(123)
:ok
iex> Vx.Number.integer() |> Vx.validate!(123.0)
:ok
iex> Vx.Number.integer() |> Vx.validate!(123.4)
** (Vx.Error) must have no decimal places
iex> Vx.Number.integer() |> Vx.validate!("foo")
** (Vx.Error) must be a number
Requires the number to be less than the given value.
Requires the number to be less than or equal to the given value.
@spec negative(schema) :: schema when schema: numeric()
Requires the number to be negative.
@spec positive(schema) :: schema when schema: numeric()
Requires the number to be positive.
Requires the number to be in the given range.
Example
iex> Vx.Number.range(1..10) |> Vx.validate!(5)
:ok
iex> Vx.Number.range(1..10) |> Vx.validate!(11)
** (Vx.Error) must be in 1..10
@spec t() :: t()
Builds a new Number type.
Examples
iex> Vx.Number.t() |> Vx.validate!(123)
:ok
iex> Vx.Number.t() |> Vx.validate!(123.4)
:ok
iex> Vx.Number.t() |> Vx.validate!("foo")
** (Vx.Error) must be a number