Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/enricoboccadifuoco/h2o-form-validator
H2o form validator is a simple and tiny form validation library, 3KB minified, no dependecies
https://github.com/enricoboccadifuoco/h2o-form-validator
Last synced: about 1 month ago
JSON representation
H2o form validator is a simple and tiny form validation library, 3KB minified, no dependecies
- Host: GitHub
- URL: https://github.com/enricoboccadifuoco/h2o-form-validator
- Owner: enricoboccadifuoco
- Created: 2018-05-16T14:15:13.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-09T11:24:56.000Z (over 6 years ago)
- Last Synced: 2024-04-23T08:47:14.706Z (9 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NOTE: this project was developed more than 3 years ago but it's just recently published ;)
# H2o form validator
H2o form validator is a simple and tiny form validation library, 3KB minified, no dependecies.
## Install
```
npm i @enricoboccadifuoco/h2o-form-validator
```## How it works
Form Validation or single fields validation
```javascript
var formValidator = validator(domFormObject);formValidator.on('error', function(e) {
// log error
console.error(e.detail.message, e.detail.el);
});if (formValidator.validate()) {
// form is correctly validate
} else {
// validation not successful
}
```## HTML implementation
```html
Submit```
| attributes | possible values | default |
| --------------------------|---------------------------------------------------|--------------|
| data-validation | (see allowed validation types) | none |
| minlength | number | |
| maxlength | number | |
| required | Boolean | |## Events
Validation trigger the following events:
* error => returns the following params, message and DOM element
## Validation types
* url
* noProtocolUrl
* alphanumeric
* number
* alpha## Error messages
* email: Please provide a valid e-mail address
* url: Please provide a valid URL
* noProtocolUrl: empty
* alphanumeric: Letters and numbers only, please
* number: Numbers only, please
* alpha: Letters only, please## Helpers
validator object return a static object called helpers.
It contains static helper methods.* addHttp: validate a url without protocol and add http into it