is v1.0.0 Is.Validators.Fn View Source

Validation using custom functions.

Examples

iex> Is.validate(1, fn: &is_number/1)
[]

iex> Is.validate(true, fn: &is_number/1)
[{:error, [], "must satisfies &:erlang.is_number/1"}]

iex> starts_with? = fn(value, prefix) ->
...>   if String.starts_with?(value, prefix) do
...>     :ok
...>   else
...>     {:error, "must start with #{inspect prefix}"}
...>   end
...> end
iex> Is.validate("https://elixir-lang.org", fn: [starts_with?, "http"])
[]
iex> Is.validate("elixir-lang.org", fn: [starts_with?, "http"])
[{:error, [], "must start with \"http\""}]

iex> Is.validate(12, fn: {1, 2})
[{:error, [], "fn: options are invalid"}]

Link to this section Summary

Link to this section Functions