Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

form-checker-ts

guilhermeasn61MIT2.1.1TypeScript support: included

The FormChecker (form-checker-ts) is a TypeScript/JavaSctipt form validation library that supports custom validation rules like required fields, length checks, pattern matching, and custom functions. It provides asynchronous validation and flexible error

Form, Validation, Form Checker, Form validation, Custom rules, Asynchronous validation, Error handling, Field validation, Validation schema, Input validation, Flexible form checker

readme

FormChecker

tests npm downloads

A TypeScript library for flexible and customizable form validation with support for synchronous and asynchronous rules.

Features

  • Define validation rules for each form field.
  • Supports built-in validation rules such as required, checked, min, max, minLength, maxLength, equal, and regexp.
  • Supports custom asynchronous validation rules (test).
  • Handles data transformation before and after validation (onBefore, onAfter).
  • Returns detailed validation results including errors and custom or default messages.
  • Contains standard validation error messages in several languages ​​such as: English, Portuguese, Spanish, Chinese, etc.

Installation

With NPM:

npm install form-checker-ts

Or with Yarn:

yarn add form-checker-ts

Example Usage

import { formChecker, type FormCheckerSchema } from 'form-checker-ts';

type Data = {
    name: string;
    email: string;
    password: string;
    password_confirm: string;
};

const schema : FormCheckerSchema<Data> = {
    name: { required: true, minLength: 3, maxLength: 30 },
    email: { required: true, minLength: 5, maxLength: 50 },
    password: { required: true, minLength: 6, maxLength: 20, regexp: [/[a-z]/, /[A-Z]/, /[0-9]/] },
    password_confirm: { required: { ifFilled: 'password' }, equal: 'password' }
};

const data : Data = {
    name: 'Guilherme',
    email: 'contato@gn.dev.br',
    password: 'Q1w2E3r4',
    password_confirm: 'Q1w2E3r4'
};

formChecker(schema, data, 'pt').then(result => {
    console.log(result);
});

Author

License

This project is under the MIT license - see the LICENSE file for details.