https://github.com/avil13/form-validation
https://github.com/avil13/form-validation
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/avil13/form-validation
- Owner: avil13
- Created: 2019-10-17T19:49:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-17T20:30:54.000Z (over 5 years ago)
- Last Synced: 2024-10-11T17:18:29.508Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Form-Validation
```html
Go
```
```js
import { Validator } from 'form-validation';Validator({
form: '#form', // optionalrules: {
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
}
```