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
npm install form-checker-ts
required, checked, min, max, minLength, maxLength, equal, and regexp.
test).
onBefore, onAfter).
bash
npm install form-checker-ts
`
Or with Yarn:
`bash
yarn add form-checker-ts
`
Example Usage
`ts
import { formChecker, type FormCheckerSchema } from 'form-checker-ts';
type Data = {
name: string;
email: string;
password: string;
password_confirm: string;
};
const schema : FormCheckerSchema = {
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);
});
``