Introduction
LIVR (Language Independent Validation Rules) is a specification for describing data validation rules as plain data. You write the rules once, as a structure that looks like the data it validates, and any LIVR implementation, in any language, validates the data the same way:
- it returns only the fields that have rules, so everything else is dropped;
- it reports errors for all fields at once, as readable codes shaped like your data;
- it can also clean the data on the way: trim strings, lowercase emails, set defaults.
rules
input
Invaliderrors
{
"name": "REQUIRED",
"email": "WRONG_EMAIL",
"age": "TOO_LOW"
}Because the rules are data, you can store them in JSON, send them from the server to the browser, and use the same schema in services written in different languages. The specification includes a test suite that every implementation runs, so they all behave the same way.
Where to go next
- Motivation: the problems with typical validators that LIVR solves.
- Core concepts: the specification, and how LIVR compares to JSON Schema.
- Principles: the requirements every LIVR validator meets.
- Examples: editable examples for common cases.
- Validation rules: the reference for every standard rule.
- Implementations: pick a library for your language.
Articles and talks
- LIVR: Data Validation Without Any Issues, by the creator of LIVR
- Language Independent Validation Rules (LIVR) for Perl 6, Perl 6 Advent Calendar
- Talk on LIVR 2.0 at the OSDN-UA 2017 conference (Russian)
- LIVR: language independent validation rules, article on Habr (Russian)
- Article on LIVR and its Perl implementation in the PragmaticPerl magazine (Russian)