Type Alias StringValidator

StringValidator: Validator<string, string[]> & {
    maxLength: (n: number) => StringValidator;
    minLength: (n: number) => StringValidator;
}

A validator that can validate a string value.

Type declaration

  • maxLength: (n: number) => StringValidator

    Checks if the string's length is equal or lower than n.

    const validator = avery.string().maxLength(5);
    console.log(validator.validate('hello').isOk()); // Output: true
    console.log(validator.validate('hello world').isOk()); // Output: false
  • minLength: (n: number) => StringValidator

    Checks if the string's length is equal or greater than n.

    const validator = avery.string().minLength(5);
    console.log(validator.validate('hello').isOk()); // Output: true
    console.log(validator.validate('hi').isOk()); // Output: false
const validator = avery.string();
const result = validator.validate('hello');
console.log(result.isOk()); // Output: true