gadgets
Version:
Reusable React UI widgets - This is my widget library. There are many like it, but this one is mine...
50 lines (49 loc) • 1.97 kB
TypeScript
export declare type ValidatorFn = (text: string, option?: any) => boolean;
/**
* A container class used to hold validation code. Creating an instance
* of this class guarantees that the validation function, success, and failure
* information is available in the instance. The validator is then used
* by a TextField control to call the validation routine within the class.
*
* #### Examples:
*
* ```javascript
* import {Validator} from 'gadgets';
*
* const x = new Validator(
* (value: string) => {
* return true;
* },
* 'failure',
* 'success'
* );
* ```
*
* The function passed to the `Validator` class returns a boolean value.
* If true is returned, then the validation call is successful, otherwise
* validation has failed. The success/failure messages are associated
* with this validation routine and can be used to prompt with validation
* info for this object.
*
* These instances are passed to the `validators` array list property on the
* `TextField` control. The `TextField` calls the `validate()`, with
* the input data to determine, if the current state of that data is
* valid. This validators array can hold multiple instances of these
* validation classes (generally different validations). The validation
* routine in the `TextField` will iterate through this array and use
* the function and success/failure to perform this validation.
*
*/
export declare class Validator {
private _failure;
private _success;
constructor(fn: ValidatorFn, failure: string, success?: string);
readonly failure: string;
readonly success: string;
validate: ValidatorFn;
}
export declare function validateMaxLength(length: number): Validator;
export declare function validateMinLength(length: number): Validator;
export declare function validateEmail(): Validator;
export declare function validateURL(): Validator;
export declare function validateRegex(regex?: RegExp): Validator;