Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Data validation library for Erlang
branch: master

Removes minor warnings in validaterl

latest commit 7694cc478f
Yurii Rashkovskii authored
Failed to load latest commit information.
include Adds #type validator to validaterl
src Removes minor warnings in validaterl
.gitignore Adds a short README
rebar.test.config Renames rebar.config to rebar.test.config so that validaterl doesn't …


Validaterl is a simple Erlang library for validating (input) data.

Validation Primitives

Using records defined in validaterl/include/validaterl.hrl one can check individual values against validators.

For example:

>  validaterl:validate(1, #range{ to = 10 })
>  validaterl:validate(1, #range{ to = 0 })

Also, if the second argument is not a validator, it will be matched against the first argument:

>  validaterl:validate(1, 1).
>  validaterl:validate(1, 2).
>  validaterl:validate(1, 0).

Custom Validators

One can define custom validators using this layout:

-record(my_validator, {
                        '$validator' = fun mymodule:myvalidator/2,
                        ... %% rest of arguments

Validation Sheets

Instead of running individual validations, you can define so called "validation sheets" and test them using validaterl:validate/1.

Validation sheet is a list of validations in the following format:

{Name :: any(), Value :: any(), Spec :: spec()}

For example:

 {'', Username, #length{ is = #range{ from = 3, to = 16 } }},
 {'', Email, #length{ is = #range { from = 3, to = 255 } }},
 {'user.age', Age, #numericality{ allow_string = true }}

Just as an example, if you try to put a string with a non-numeric value into Age, you'll get this:

             #numericality{'$validator' = #Fun<validaterl.validate.2>,
                           allow_undefined = false,allow_null = false,
                           allow_string = true,allow_empty = false,allow_rest = false,
                           allow_float = true,default = 0},
Something went wrong with that request. Please try again.