UNPKG

multiform-validator

Version:

Javascript library made to validate, several form fields, such as: email, images, phone, password, cpf etc.

31 lines (30 loc) 974 B
import type { ValidateFunctions } from "./types"; interface OptionsParams { minLength?: number; maxLength?: number; errorMsg?: (string | null)[]; } /** * @param name * @param minLength * @param maxLength * @param errorMsg * @default minLength number: default: 1 * @default maxLength number: default: 20 * @example validateName('John', { minLength: 2, maxLength: 20 }); // Returns { isValid: true, errorMsg: null } * @info minLength cannot be greater than maxLength * @description This function returns 6 errors in the following order, * * default: * * [ 'Name cannot be empty', 'Name cannot contain numbers', 'Name cannot contain special characters', 'This name is not valid', 'Name too big, try again', ]; * @returns An object with 'isValid' (boolean) and 'errorMsg' (string) properties. */ declare function validateName(name: string, { minLength, maxLength, errorMsg }?: OptionsParams): ValidateFunctions; export default validateName;