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

https://github.com/avil13/form-validation


https://github.com/avil13/form-validation

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# Form-Validation

```html









Go

```

```js
import { Validator } from 'form-validation';

Validator({
form: '#form', // optional

rules: {
name: 'required|between:3,20',
email: 'required|email',
password: 'minLenght:4|confirmed'
},

// optional ***
messages: {
required: 'This is an important field, do not be lazy.',
// field.rule
'email.email': 'I need your clothes, boots and Email'
},

attributes: {
password: 'Secret field'
},

options: {
cached: false
},

submit(event) {
if (event.isValid) {
console.log('Good');
}
},

onInput(event) {
console.log(event);
}
});
```
---

## If app size are important and do not want to load all rules

```js
import { MakeValidator } from 'form-validation/make';
import { required, email } from 'form-validation/rules';

const isEqualNumberOne = {
name: 'isEqualNumberOne',
rule(params) {
return params.value === '1';
},
message: 'Some text for :isEqualNumberOne', // optional
attribute: 'this key name' // optional
};

const Validator = MakeValidator([required, email, isEqualNumberOne]);
```

### Fields key pattern

```js
rules: {
'name': 'minLenght:3', // The rule for a single field
'list.*': 'required', // The rule for array fields
'list.*.email': 'email', // Rule for special fields in the array
}
```