https://github.com/99x-incubator/js-input-validator
Simple JS Input Validator
https://github.com/99x-incubator/js-input-validator
js validate-js validation-library
Last synced: 9 months ago
JSON representation
Simple JS Input Validator
- Host: GitHub
- URL: https://github.com/99x-incubator/js-input-validator
- Owner: 99x-incubator
- License: mit
- Created: 2018-04-25T12:05:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T15:16:36.000Z (over 3 years ago)
- Last Synced: 2025-01-03T21:41:49.253Z (over 1 year ago)
- Topics: js, validate-js, validation-library
- Language: JavaScript
- Homepage:
- Size: 950 KB
- Stars: 4
- Watchers: 4
- Forks: 9
- Open Issues: 36
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# js-input-validator
[](https://www.npmjs.com/package/js-input-validator)
[](https://github.com/99xt-incubator/js-input-validator/blob/master/LICENSE)
Simple JS Input Validator
## Installation
To install this library, run;
```
npm i -S js-input-validator
```
## Usage
```js
import Validator from "js-input-validator";
// Schema
const schema = {
field1: {
name: "field 1",
type: "number",
required: true,
length: {
min: 1,
max: 3
},
min: 1
},
field2: {
name: "field 2",
type: ["string", "number"],
required: true,
min: 3,
validate: function(value, values={}) {
return true;
}
},
field3: {
name: "field 3",
type: "number",
required: false,
min: 3,
max: 5
},
field4: {
name: "field 4",
type: "email"
}
};
// Values
const errors = new Validator(schema).run({
field1: "s",
field3: 4,
field4: "sasadsa@adsa"
});
// Run Validator with `run` method and get error object
const errors = new Validator(schema).run(values);
// Run Validator with `isValid` method
const data = new Validator(schema);
if (data.isValid()) {
// Valid
} else {
// Invalid
}
```
## License
MIT