xBacon
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!
Available validations
- CPF
Planned
- CNPJ
- CEP
- Titulo Eleitor
How do I use it ?
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
Installation
If available in Hex, the package can be installed as:
-
Add
xbaconto your list of dependencies inmix.exs:
```elixir
def deps do
[{:xbacon, "~> 0.1.0"}]
end
```-
Ensure
xbaconis started before your application:
```elixir
def application do
[applications: [:xbacon]]
end
```Icons made by Freepick