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.
- Host: GitHub
- URL: https://github.com/retro/javascript-object-validator
- Owner: retro
- Created: 2008-08-11T20:40:20.000Z (over 17 years ago)
- Default Branch: master
- Last Pushed: 2008-08-14T13:34:26.000Z (over 17 years ago)
- Last Synced: 2025-05-05T01:06:31.546Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 104 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README
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.