UNPKG

@try-at-software/input-elements

Version:

A package providing different input elements that are extensible and easily configurable for your custom needs.

24 lines (23 loc) 994 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.restrictMaximumLength = exports.restrictMinimumLength = void 0; function restrictMinimumLength(minLength, errorMessage) { return (newValue) => { let error = ''; // If the new value is shorter than expected, return an error message. if (newValue.length < minLength) error = errorMessage || `The value should be longer than ${minLength} characters!`; return error; }; } exports.restrictMinimumLength = restrictMinimumLength; function restrictMaximumLength(maxLength, errorMessage) { return (newValue) => { let error = ''; // If the new value is longer than expected, return an error message. if (newValue.length > maxLength) error = errorMessage || `The value should be shorter than ${maxLength} characters!`; return error; }; } exports.restrictMaximumLength = restrictMaximumLength;