Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
* email
* 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