@modular-forms/react
Version:
The modular and type-safe form library for React
12 lines (11 loc) • 354 B
JavaScript
/**
* Creates a validation functions that validates the length of a string or array.
*
* @param requirement The minimum string or array length.
* @param error The error message.
*
* @returns A validation function.
*/
export function minLength(requirement, error) {
return (value) => value?.length && value.length < requirement ? error : '';
}