mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 12:25:44 -05:00
17 lines
502 B
TypeScript
17 lines
502 B
TypeScript
type TextValidator = ({ value }: { value: string }) => string | undefined;
|
|
|
|
/** A text field validator that requires a value no longer than `max` characters. */
|
|
export const requiredWithMaxLength =
|
|
(max: number, missing: () => string, tooLong: () => string): TextValidator =>
|
|
({ value }): string | undefined => {
|
|
if (value.length < 1) {
|
|
return missing();
|
|
}
|
|
|
|
if (value.length > max) {
|
|
return tooLong();
|
|
}
|
|
|
|
return undefined;
|
|
};
|