# valid-form

> ```js const { Validator } = require('valid-form');

Latest version **1.0.0** (published 2020-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install valid-form
pnpm add valid-form
yarn add valid-form
bun add valid-form
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-06-03 |
| First published | 2020-06-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | 12.16.3 |
| Dependencies | 0 |
| Unpacked size | 33.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | edo92 |
| Maintainers | edo1792 |

## Links

- npm: https://www.npmjs.com/package/valid-form
- npm.io page: https://npm.io/package/valid-form

## Recent versions

- 1.0.0 (latest) — 2020-06-03
- 0.1.2 — 2020-06-03
- 0.1.1 — 2020-06-02
- 0.1.0 — 2020-06-02

## README

# Easy Form Validation

```js
const { Validator } = require('valid-form');

let validate = new Validator();

const form = {
  email: 'johnDoe@gmail.com',
  fullName: 'John Doe',
  username: 'johnDoe123',
  password: 'Asdfasdaf123',
  repPassword: 'Asdfasdaf123',
};

validate.formValidation(form, (validated) => {
  console.log(validated);
});
```

## Installation

```
npm install form-validate
```

## Usage

```js
Pass form object to --> validate.formValidation(form);
```

```js
import { Validator } from 'valid-form';

let validate = new Validator();

const validated = await validate.formValidation(form);
console.log(validated);
```

or

```js
const { Validator } = require('valid-form');

const validate = new Validator();

validate.formValidation(form), (data) => {
    consle.log(data);
});
```

### Custom validation

<small>Pass custom pattern (regex) or action function</small>
<small>pattern must be in regex format</small>
<small>with action pass error message</small>

```js
const { Validator } = require('../dist');

let validate = new Validator({
  username: {
    pattern: '^[a-zA-Z0-9]([._](?![._])|[a-zA-Z0-9]){3,18}[a-zA-Z0-9]$',
  },
  fullName: {
    action: (form) => {
      return form.username !== form.fullName;
    },
    message: 'Something is wrong'
  },
});

const form = {
  fullName: 'first last',
  username: 'username_123',
};

// Validate form set status to state
validate.formValidation(form, (validated) => {
  console.log(validated);
```

### Validate

default validator has validation for -->
-> email
-> username
-> fullName
-> password
-> repPassowrd

---
_Source: https://npm.io/package/valid-form · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
