# rn-validation

> Supporting component helping validating values

Latest version **1.1.0** (published 2020-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install rn-validation
pnpm add rn-validation
yarn add rn-validation
bun add rn-validation
```

## Health

**Score 40/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-09-04 |
| First published | 2019-09-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 79.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Karona Tourn |
| Maintainers | tournkarona |
| Keywords | rn-vaidations, react-validations, react-native-validations, validations, validating, react-native-validating |

## Links

- npm: https://www.npmjs.com/package/rn-validation
- Repository: https://github.com/Karona-Tourn/rn-validation
- Homepage: https://github.com/Karona-Tourn/rn-validation#readme
- Issues: https://github.com/Karona-Tourn/rn-validation/issues
- npm.io page: https://npm.io/package/rn-validation

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-09-04
- 1.0.0 — 2019-09-18

## README

# rn-validation

Supporting component helping validating values

## Features

- Provide validation rules
- Able to create custom validation rules
- Easy to use

## Installation

```sh
npm install rn-validation
```

or

```sh
yarn add rn-validation
```

## Usage

```js
import { createRef } from 'react';
import { ValidationGroup, Validator, ValidationRules } from 'rn-validation';

const validation = createRef();

<ValidationGroup
  ref={validation}
  onValidated={({ validated, validatedErrors }) => {
    if (validated) {
      alert('Validated successfully!');
    } else {
      alert(validatedErrors[0].firstValidatedErrorMessage);
    }
  }}
>
  <Validator
    getValidatedValue={() => value}
    validations={[
      ValidationRules.isNotEmpty,
      ValidationRules.isLengthLessThanOrEqualTo(20),
    ]}
    errorMessages={['Cannot be empty', 'Value length cannot exceed 20']}
  >
    {({ validated, firstValidatedErrorMessage }) => {
      return (
        <View>
          <TextInput
            value={value}
            style={{ borderWidth: 1, borderColor: validated ? 'grey' : 'red' }}
          />
          {validated ? null : <Text>{firstValidatedErrorMessage}</Text>}
        </View>
      );
    }}
  </Validator>
</ValidationGroup>;

// Call the method to start validating all validators inside the group
validation.current.validate();
```

### **ValidationGroup**

#### Props

| Name        | Type     | Required | Default | Description                                 |
| ----------- | -------- | :------: | :-----: | ------------------------------------------- |
| onValidated | function |    ❌    |  null   | Callback invoked after validating completed |

#### Methods

| Name     | Description                |
| -------- | -------------------------- |
| validate | Invoke to start validating |

### **Validator**

#### Props

| Name                        | Type       | Required | Default | Description                                                                               |
| --------------------------- | ---------- | :------: | :-----: | ----------------------------------------------------------------------------------------- |
| validations                 | function[] |    ✔️    |   []    | Array of validating functions to be used for validating                                   |
| errorMessages               | string[]   |    ❌    |   []    | Array of error messages corresponding the validation function array                       |
| getValidatedValue           | function   |    ✔️    |         | Function returning the value to be validated                                              |
| getExtraDataAfterValidating | function   |    ❌    |         | Function returning the extra data to be passed as argument to callback of ValidationGroup |
| children                    | function   |    ✔️    |         | Children must be function return an element                                               |

#### Methods

| Name     | Description                |
| -------- | -------------------------- |
| validate | Invoke to start validating |

### **ValidationRules**

- isNotEmpty
- isLengthLessThan
- isLengthLessThanOrEqualTo
- isLengthBetween
- isEqual
- isExactlyEqual
- matchRegExp
- isBetween
- isLessThan
- isLessThanOrEqualTo
- isGreaterThan
- isGreaterThanOrEqualTo
- requireNumericDigits
- isEmail
- isNotEmptyTrim

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

## License

MIT

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