Files
GeneIT/geneit_app/src/utils/form_utils.ts
Pierre HUBERT 1a890844ef
All checks were successful
continuous-integration/drone/push Build is passing
Add an accommodations reservations module (#188)
Add a new module to enable accommodations reservation

![](https://gitea.communiquons.org/attachments/de1f5b12-0a93-40f8-b29d-97665daa6fd5)

Reviewed-on: #188
2024-06-22 21:30:26 +00:00

22 lines
596 B
TypeScript

import { LenConstraint } from "../api/ServerApi";
/**
* Check if a constraint was respected or not
*
* @returns An error message appropriate for the constraint
* violation, if any, or undefined otherwise
*/
export function checkConstraint(
constraint: LenConstraint,
value: string | undefined
): string | undefined {
value = value ?? "";
if (value.length < constraint.min)
return `Veuillez indiquer au moins ${constraint.min} caractères !`;
if (value.length > constraint.max)
return `Veuillez indiquer au maximum ${constraint.max} caractères !`;
return undefined;
}