Talos.Types.StringType (Talos v1.12.1) View Source

Type for check value is string

For example:

  iex> import Talos, only: [string: 1]
  iex> short_domain = string(length: 3)
  iex> domains_list = ["cats", "foo", "baz", "pron"]
  iex> Enum.filter(domains_list, fn str -> Talos.valid?(short_domain, str) end)
  ["foo", "baz"]

Additional parameters:

min_length, same as String.length(str) <= max_length

max_length, same as String.length(str) >= max_length

length, same as String.length(str) >= length

regexp, same as String.match?(str, regexp)

Link to this section Summary

Functions

Callback implementation for Talos.Types.errors/2.

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

Link to this section Types

Specs

t() :: %{
  __struct__: atom(),
  min_length: nil | integer(),
  length: nil | integer(),
  max_length: nil | integer(),
  allow_nil: nil | boolean(),
  allow_blank: nil | boolean(),
  regexp: nil | Regex.t(),
  example_value: any()
}

Link to this section Functions

Link to this function

errors(string_type, value)

View Source

Specs

errors(t(), binary()) :: [String.t()]

Callback implementation for Talos.Types.errors/2.

Specs

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

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