View Source EctoKsuid.Validator (ecto_ksuid v0.3.0)
Validates if a given value is a valid EctoKsuid
Link to this section Summary
Link to this section Functions
Validates a given ksuid.
Will check that the value:
- has the correct length
- only includes the base62 alphabet
examples
Examples
iex> EctoKsuid.Validator.is_valid?("2mepXCkbpLkY0hrFkORS5khkcGT")
{:ok, valid_ksuid}
iex> EctoKsuid.Validator.is_valid?(nil)
:error
@spec is_valid?(String.t() | any(), EctoKsuid.Options.t()) :: {:ok, String.t()} | :error
Validates a given EctoKsuid.
Will check that the value:
- has the configured prefix
- has the correct length
- only includes the base62 alphabet
examples
Examples
iex> EctoKsuid.Validator.is_valid?("2mepXDSdV0JSCqrGCJPX2WsBGDj", %EctoKsuid.Options{prefix: ""})
{:ok, valid_ksuid}
iex> EctoKsuid.Validator.is_valid?("prefix_2mepXCGBse2JRbrM3BeX4NEL93b", %EctoKsuid.Options{prefix: "prefix_"})
{:ok, valid_ksuid}
iex> EctoKsuid.Validator.is_valid?(nil, %EctoKsuid.Options{prefix: ""})
:error
iex> EctoKsuid.Validator.is_valid?("wrong_2mepXD9zNNZKG4CA8OKjhdZAgmL", %EctoKsuid.Options{prefix: "prefix_"})
:error