Add headcode validation and test
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user