# validator-react

> Validation package for react, inspired by laravel validation.

Latest version **1.0.3** (published 2019-07-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install validator-react
pnpm add validator-react
yarn add validator-react
bun add validator-react
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2019-07-26 |
| First published | 2019-07-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Akhtar Husain |
| Maintainers | akhtar-husain |
| Keywords | React, Validation, JS, validator |

## Links

- npm: https://www.npmjs.com/package/validator-react
- Repository: https://github.com/akhtar-husain/react-validator
- Homepage: https://github.com/akhtar-husain/react-validator#readme
- Issues: https://github.com/akhtar-husain/react-validator/issues
- npm.io page: https://npm.io/package/validator-react

## Dependencies (1)

- [validator](https://npm.io/package/validator.md) ^11.1.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.3 (latest) — 2019-07-26
- 1.0.2 — 2019-07-26
- 1.0.1 — 2019-07-26

## README

# React Validator
Validation package for react, inspired by laravel validation.

## Getting Started
Install it using the npm package manager.

```
npm install validator-react
```

## Usage Example
```JS
import validate from 'validator-react';

const rules = [
  {
    field: 'email',
    validations: ['required', 'email'],
    name: 'User email' // used to show in error message
  },
  {
    field: 'password',
    validations: ['required', 'password', 'confirm', 'digit:10'],
    name: 'Password' // used to show in error message
  }
];

class Login extends Component {
  state = {
    errors: {},
    isValidForm: true,
    formFields: {
      emai: '',
      password: ''
    }
  };
  
  _validate() {
    const { formFields } = this.state;
    const validRes = validate(formFields, rules);
    this.setState(() => ({ errors: validRes.errors, isValidForm: validRes.isValid }));
    return validRes.isValid;
  }
}
```

## Available rules
* ```required``` field must not be empty or null or undefined.

* ```numeric``` field must be a numeric value.

* ```email```  field must be a valid email address.

* ```digit```  example - ```digit:10``` field must be digit with fixed length of 10.

* ```url```  field must be a valid url.

* ```password```  field must conatain 8-14 characters and atleast one capital character and one digit.

* ```confirm```  field must me equals to the fieldComfirm field. example - 
```
{
  field: 'password',
  validations: ['required', 'password', 'confirm', 'digit:10'],
  name: 'Password' // used to show in error message
}
```
then in the formFields there must me a field named passwordConfirm field which holds the same value as password.

* ```min```  example - ```min:10``` field must hold the length greater than or equal to 10 characters.

* ```max```  example - ```max:10``` field must hold the length less than or equal to 10 characters.


## Authors
* [Akhtar Husain](https://github.com/akhtar-husain)

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