Separate input validation and extend PIS functions

This commit is contained in:
Fred Boniface
2025-03-12 15:33:37 +00:00
parent 071328bdd0
commit d20d981190
4 changed files with 64 additions and 6 deletions

View File

@@ -0,0 +1,25 @@
import { ValidationError } from "../errors";
export function validatePisCode(code: string): boolean {
const codeRegex = /^\d{4}$/;
if (!codeRegex.test(code)) {
throw new ValidationError("Invalid input: code must be a four-character string consisting of only numerals");
}
return true;
}
export function validateTiploc(tiploc: string): boolean {
const tiplocRegex = /[a-zA-z0-9]{4,7}/;
if (!tiplocRegex.test(tiploc)) {
throw new ValidationError("Invalid input: TIPLOC must be between four and seven characters");
}
return true;
}
export function validateCrs(crs: string): boolean {
const crsRegex = /[a-zA-z]{3}/;
if (!crsRegex.test(crs)) {
throw new ValidationError("Invalid input: CRS/3ALPHA must be exactly three letters")
}
return true;
}