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

https://github.com/dammy001/react-form-validation-hook

react form validation hook
https://github.com/dammy001/react-form-validation-hook

hooks react react-hooks validation-library validation-rules validations

Last synced: 23 days ago
JSON representation

react form validation hook

Awesome Lists containing this project

README

          

# React Form Validation Hook

### Install

#### NPM

```
npm i @damilaredev/react-form-validation-hook
```

#### Yarn

```
yarn add @damilaredev/react-form-validation-hook
```

### Usage

```javascript
import React, { FC, useState } from 'react';
import useFormValidator from '@damilaredev/react-form-validation-hook'

const Login: FC = () => {
const { values, errors, updateField, isAllFieldsValid } = useFormValidator({
email: {
value: '',
checks: 'required|email', //using pipe to seperate validation rule
},
password: {
value: '',
checks: 'required|digitsBetween:3,5|in:damilare,maxwell,notIn:christiana',
}
});

const submitCredentials = async (e: FormEvent) => {
e.preventDefault();

if (!isAllFieldsValid()) return false;

const { email, password } = values;
};

return (

{errors && {errors[key]}}
)
};
```

## Available validation rules

- required
- email
- numeric
- alphabetic
- alphaNumeric
- maxLength
- minLength
- phone
- url
- size
- in
- digitsBetween
- notIn
- regex
- cardNumber

stay patient more validation rules are coming...