elixir-uuid icon indicating copy to clipboard operation
elixir-uuid copied to clipboard

UUID.valid?/2

Open christhekeele opened this issue 8 years ago • 1 comments

It'd be handy for this library to provide some basic validation functions for uuids, too.

Might hack this together shortly, wanted to leave this here to remind myself in case I don't get around to it soon or somebody else want to take a stab at it.

I'm thinking it could support :version and :format opts––the format one to verify that the uuid is of a particular format, not to hint at the format of the argument for parsing purposes.

christhekeele avatar Nov 19 '17 05:11 christhekeele

I couldn't agree more. I created a helper method using UUID.info/1, but it's far from ideal:

defmodule MyApp.Aux.ValidateUUID do
  def call(uuid) do
    case UUID.info(uuid) do
      {:ok, [{:uuid, valid_uuid} | _tails]} -> {:ok, valid_uuid}
      {:error, _reason} = error -> error
    end
  end
end

librity avatar Mar 17 '21 03:03 librity