A set of validators and matchers, focusing on Brazilian needs, but general too!
Here you can find useful validations for your changeset, or just matchers if you want!
Simply import the changeset module into your model and pipe the validations on your changeset!
defmodule App.Person do
import XBacon.Changeset.CPF
# ....
def changeset(model, params \\ %{}) do
model
|> cast(params, @fields)
|> validate_required(@req_fields)
|> validate_cpf
end
end
The validators use a default field naming matching the subject being validated,
for example, if you are validating CPF with validate_cpf/2
you can provide an
atom as second arity if your field is not named :cpf
The package can be installed as:
- Add
xbacon
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:xbacon, "~> 0.1.0"}]
end
```
- Ensure
xbacon
is started before your application:
```elixir
def application do
[applications: [:xbacon]]
end
```
Icons made by Freepick