This is aims to be an elixir clone of the NPM Validator package.
Currently, only UUIDs, emails and URLs are supported.
If available in Hex, the package can be installed as:
- Add
validator
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:validator, "~> 0.2.0"}]
end
```
-
Run
mix deps.install
-
Ensure
validator
is started before your application:
```elixir
def application do
[applications: [:validator]]
end
```
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:api_id, :some_url, :some_email])
|> validate_required([:api_id, :some_url])
|> Validator.validate_uuid(:api_id)
|> Validator.validate_email(:some_email)
|> Validator.validate_url(:some_url)
end