View Source Talos.Types.NumberType (Talos v1.12.2)

Type for check value is number

For example:


  iex> import Talos, only: [number: 1]
  iex> percents = number(gteq: 0, lteq: 100)
  iex> Talos.valid?(percents, 42)
  true
  iex> Talos.valid?(percents, -15)
  false
  iex> Talos.valid?(percents, 30.0)
  true

Additional parameters:

allow_nil - allows value to be nil

gteq - greater than or equal, same as >=

lteq - lower than or equal, same as <=

gt - lower than, same as >

lt - lower than, same as <

Summary

Functions

Callback implementation for Talos.Types.errors/2.

Callback implementation for Talos.Types.valid?/2.

Types

@type t() :: %{
  __struct__: atom(),
  gteq: nil | number(),
  lteq: nil | number(),
  gt: nil | number(),
  lt: nil | number(),
  allow_nil: boolean(),
  example_value: any(),
  type: :float | :integer | nil
}

Functions

Link to this function

errors(number_type, value)

View Source
@spec errors(t(), binary()) :: [String.t()]

Callback implementation for Talos.Types.errors/2.

@spec valid?(t(), any()) :: boolean()

Callback implementation for Talos.Types.valid?/2.