https://github.com/nicklayb/simplevalidator
Simple validator for your dom inputs
https://github.com/nicklayb/simplevalidator
Last synced: 10 months ago
JSON representation
Simple validator for your dom inputs
- Host: GitHub
- URL: https://github.com/nicklayb/simplevalidator
- Owner: nicklayb
- License: mit
- Created: 2017-02-03T03:04:26.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-03T03:47:50.000Z (over 9 years ago)
- Last Synced: 2025-04-03T06:37:29.357Z (about 1 year ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleValidator
###### By Nicolas Boisvert :: nicklay@me.com
### Simple validator for your dom inputs
## How-to
You first instanciate you `SimpleValidator` object by passing in an object with your rules, what to do when they're valid and what to do when they're not valid. And after all, all you need to do is call the `check()` method on your SimpleValidator object.
```
const validator = new SimpleValidator({
rules: {
name: () => {
return /* Your name validation */;
},
},
valid: () => {
console.log('valid');
},
notValid: () => {
console.log('notValid');
}
});
validator.check();
```
### Other methods
#### Adding validator
There is also other methods like `push` or `pushMany` that allow you to add additionnal validators.
```
validator.push('age', function() {
return age > 18;
});
validator.push({
age: function() {
return age > 18;
},
/* Other validations */
});
```
#### Removing validator
You can remove a validator within the `removeRule` method or validate the existance of a method with `hasRule`
```
validator.hasRule('age'); // Return true;
validator.removeRule('age');
validator.hasRule('age'); // Return false;
```
## Conclusion
Thank you for using, testing and improving it and feel free to contact me for any question.
Ending joke :
> **Q** : What do computers and air conditioners have in common? **A** : They both become useless when you open windows