Separate input validation and extend PIS functions
This commit is contained in:
25
src/inputValidation/inputValidation.ts
Normal file
25
src/inputValidation/inputValidation.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user