1
0
Fork 0
fahrPool/web/lib/orte-fahrzeuge/validate-fahrzeug.ts

19 lines
782 B
TypeScript

export type FahrzeugValidationResult =
| { valid: true; kennzeichen: string; marke: string | null; modell: string | null }
| { valid: false; error: string };
export function validateFahrzeug(input: {
kennzeichen: FormDataEntryValue | null;
marke: FormDataEntryValue | null;
modell: FormDataEntryValue | null;
}): FahrzeugValidationResult {
const kennzeichen = typeof input.kennzeichen === "string" ? input.kennzeichen.trim() : "";
const marke = typeof input.marke === "string" ? input.marke.trim() : "";
const modell = typeof input.modell === "string" ? input.modell.trim() : "";
if (!kennzeichen) {
return { valid: false, error: "Bitte ein Kennzeichen eingeben." };
}
return { valid: true, kennzeichen, marke: marke || null, modell: modell || null };
}