Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/botic/validator
A validator for RingoJS
https://github.com/botic/validator
javascript ringojs validation
Last synced: about 1 month ago
JSON representation
A validator for RingoJS
- Host: GitHub
- URL: https://github.com/botic/validator
- Owner: botic
- License: mit
- Created: 2014-04-01T15:26:28.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-11-14T15:22:31.000Z (about 7 years ago)
- Last Synced: 2023-03-11T07:58:41.799Z (over 1 year ago)
- Topics: javascript, ringojs, validation
- Language: JavaScript
- Size: 110 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
validator
=========Validator is a lightweight validation and sanitization library for RingoJS.
It’s using the `ringo/utils/strings` module for string validation.## Example
In a Web application you can use the validator to validate the submitted data:
```javascript
var validator = new Validator(req.postParams);validator.validate("username", true) // true --> trim the value
.isDefined("Username is missing!")
.hasMinLength(3, "Username is too short!")
.hasMaxLength(255, "Username is too long!");validator.validate("email")
.isDefined("Email address is missing!")
.isEmail("Invalid email address!");validator.validate("age")
.isInt("Invalid age!")
.toInt().isGreaterThan(17, "You need to be 18 years old!");
// Retrieve a single value
log.debug("Age: " + validator.getValue("age"));if (validator.hasFailures()) {
// Display errors
return respone.html(
// returns an object with grouped error messages
// e.g. { "age": ["Invalid age!"], "email": […] }
validator.getMessages()
);
}
```## API Reference
* [Release 2.1.0](https://github.com/botic/validator/wiki/API-Reference-Release-2.1.0)
* [Release 2.0.0](https://github.com/botic/validator/wiki/API-Reference-Release-2.0.0)## Changelog
* **Release 2.1.0**
* adds `hasUnvalidatedProperties()` to check if the validated object has no additional properties defined
* **Release 2.0.0**
* all validating functions are now prefixed with `is` or `has` e.g. `minLength()` changed to `hasMinLength()`
* Changed the semantics of `.optional()`, which will no longer execute
subsequent validation functions or converts.
* The default value provided in `.optional()` will be returned by `validator.getValue()`now[ ![Codeship Status for botic/validator](https://codeship.com/projects/b77d7cf0-9c82-0131-4c86-5af6bd151f39/status?branch=master)](https://codeship.com/projects/17769)