UNPKG

react-proforma

Version:

React Proforma helps you build simple to complex web forms with ease in React. -- Simplicity where you want it. Flexibility where you need it.

52 lines (51 loc) 1.65 kB
declare class FieldValidator { private _value; private errors; constructor(_value: string); private _push; min(length: number, msg?: string): this; max(length: number, msg?: string): this; required(msg?: string): this; integer(msg?: string): this; float(msg?: string): this; email(msg?: string, rgx?: RegExp): this; regex(rgx: RegExp, msg?: string): this; equals(comparedString: string, msg?: string): this; custom(fn: () => string | undefined): this; end(): string[] | null; } /** * @function * Exposes the FieldValidator class which allows you to chain validation methods together and * produce an array of error messages that are attached to the "errors" object inside the * "ProformaBag" of properties and methods. To be used inside the "validationObject" prop * passed to the Proforma component. See README for more detailed examples. * @example * <Proforma * config={{ * {...} * validationObject: { * field_one: (values) => { * return fieldValidator(values.field_one) * .required() * .min(5) * .max(25) * .end(); * }, * email: (values) => { * return fieldValidator(values.email) * .required() * .email('Please enter a valid email address!') * .end(); * } * } * }} * > * {...} * </Proforma> * * @param {string} value - the value to be validatated (e.g. values.name, values.email, values.password, etc.) * @returns {FieldValidator} FieldValidator class instance */ export declare function fieldValidator(value: string): FieldValidator; export {};