1.3.0 • Published 11 months ago

@damilaredev/react-form-validation-hook v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

React Form Validation Hook

Install

NPM

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

Yarn

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

Usage

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<HTMLFormElement>) => {
  e.preventDefault();

  if (!isAllFieldsValid()) return false;

  const { email, password } = values;
 };

 return (
     <input className="w-full h-5 p-3" type="text" name="email" placeholder="Email Address" onChange={updateField} />
      {errors && <span className="text-red-500 text-sm mt-1">{errors[key]}</span>}
 )
};

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...

1.2.0

11 months ago

1.3.0

11 months ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago