Skip to main content

Function: lengthBetween()

lengthBetween(min, max, errorMessage?): Validator<string, string, string>

Defined in: validation/validators/index.ts:84

Validates string length within a range.

Parameters

min

number

Minimum length

max

number

Maximum length

errorMessage?

string

Custom error message (optional)

Returns

Validator<string, string, string>

Validator that checks length range

Example

lengthBetween(3, 10)('John') // => Valid('John')
lengthBetween(3, 10)('Jo') // => Invalid(['Must be between 3 and 10 characters'])
lengthBetween(3, 10)('Very long name') // => Invalid(['Must be between 3 and 10 characters'])