Skip to content


Subversion checkout URL

You can clone with
Download ZIP
branch: master
Failed to load latest commit information.
src fix app.src file up a little
.gitignore Ignore plt files.
AUTHORS Add authors file.
LICENSE Initial commit of Deputy
Makefile use Updated readme with required rule use
rebar.config Build using native.


Deputy is a declarative data conversion and validation library for Erlang.

It is meant to be useful for handling user input and reporting reasonably useful messages back to a user.

For awesome -type based checking (which can certainly be used with this) checkout

Simple Value Usage

Rules = [{{convert, float}, <<"Must be a floating point number">>}, 
         {{'<', 10.0}, <<"Must be less than 10.0">>}],
{ok, 5.5} = deputy:check(<<"5.5">>, Rules),
{error, [<<"Must be less than 10.0">>]} =
    deputy:check(<<"40.0">>, Rules),
{error, [<<"Must be a floating point number">>]} =
    deputy:check(<<"abcd">>, Rules),

Proplist Usage

Rules = [{<<"name">> , [{required, <<"Must have a name">>}, {{regexp, <<"[a-zA-Z0-9]+">>}, <<"Must contain only alphanumerical characters">>}]}],
Attributes = [{<<"name">>, <<"##BatMan##">>}],
{error, [{<<"name">>, [<<"Must...">>]}]} = deputy:check_proplist(Attributes, Rules, []),

Addon Type Conversion and Validation

DateConvert = fun(Date) ->
    DateStr = binary_to_list(Date),
    case io_lib:fread("~4d-~2d-~2d", Date) of
        {ok, [Year, Month, Day]} ->
            {ok, {Year, Month, Day}};
        _ ->

CurrentDate = 
MinAge = 18,
%% bad age checker
CheckAge = fun(Date) ->
  Days = calendar:date_to_gregorian(Date),
  {Today, _} = calendar:local_time(),
  TodayDays = calendar:date_to_gregorian(Today),
  Age = (TodayDays - Days)/365.0,
  case Age > MinAge ->
      true -> ok
      false -> error

Rules = [{<<"birthday">>,
  [{{func, DateConvert}, <<"Must be a valid datetime string.">>},
   {{func, CheckAge}, <<"Must be at least 18 years old.">>}]}].
Something went wrong with that request. Please try again.