Add headcode validation and test

This commit is contained in:
Fred Boniface
2025-03-12 22:06:59 +00:00
parent 196cc8783b
commit 827014ea49
2 changed files with 45 additions and 1 deletions

View File

@@ -67,4 +67,15 @@ export function validateReasonCode(code: unknown): boolean {
// If it's neither a number nor a string, throw an error
throw new ValidationError("Invalid input: Reason code must be a number or a string of three digits.");
}
export function validateHeadcode(headcode: unknown): boolean {
if (typeof headcode !== "string") {
throw new ValidationError("Invalid input: Headcode must be a string");
}
if (!/^\d[A-Za-z]\d{2}$/.test(headcode)) {
throw new ValidationError("Invalid input: Headcode must be in the format dLdd where d=digit and L=letter");
}
return true;
}