View Source EctoKsuid.Validator (ecto_ksuid v0.3.0)

Validates if a given value is a valid EctoKsuid

Link to this section Summary

Functions

Validates a given ksuid.

Validates a given EctoKsuid.

Link to this section Functions

@spec is_valid?(String.t() | any()) :: {:ok, String.t()} | :error

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
Link to this function

is_valid?(value, options)

View Source
@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