https://github.com/fourkio/validator
A set of format validators for elixir
https://github.com/fourkio/validator
Last synced: 9 months ago
JSON representation
A set of format validators for elixir
- Host: GitHub
- URL: https://github.com/fourkio/validator
- Owner: fourkio
- License: other
- Created: 2016-07-14T17:10:22.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-21T06:40:11.000Z (about 9 years ago)
- Last Synced: 2025-10-21T14:56:12.402Z (9 months ago)
- Language: Elixir
- Size: 12.7 KB
- Stars: 4
- Watchers: 5
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# validator
[](https://semaphoreci.com/fourkio/validator)
This is aims to be an elixir clone of the [NPM Validator](https://github.com/chriso/validator.js) package.
Currently, only UUIDs, emails and URLs are supported.
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:
1. Add `validator` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:validator, "~> 0.2.0"}]
end
```
2. Run `mix deps.install`
3. Ensure `validator` is started before your application:
```elixir
def application do
[applications: [:validator]]
end
```
## Usage
```
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
```