An open API service indexing awesome lists of open source software.

https://github.com/retro/javascript-object-validator

Validation of Javascript objects based on system simmilar to Rails ActiveRecord validation.
https://github.com/retro/javascript-object-validator

Last synced: 8 months ago
JSON representation

Validation of Javascript objects based on system simmilar to Rails ActiveRecord validation.

Awesome Lists containing this project

README

          

Small validation framework written in Javascript. It does validation on Javascript objects, not on form fields. You can find some specs in test folder.

The main point is to allow complex validations on dependant fields.

Example:

validator = new Validator(
{test_field_1: 'Test', test_field_2: '', test_field_3: 'test.com'},
{presence_of : 'test_field_2',
email_format_of: ['test_field_3', 'test_field_2'],
with_function : {fields: 'test_field_1', with: function(fields, args){return false;}},
format_of : [{fields: ['test_field_2'], with: /SomeStringThatWillFail/ },
{fields: 'test_field_3', with: /SomeStringThatWillFail/, message: 'Custom validation message'}
]
}
)

First argument is the object you are validating, and second is validation schema. You can easily add custom validators, or use anonymous function for validations.