use isikukood library to validate in zod

This commit is contained in:
Danel Kungla
2025-08-04 11:32:41 +03:00
parent 6ba33a99b2
commit 0254805743

View File

@@ -1,5 +1,19 @@
import Isikukood from 'isikukood';
import { z } from 'zod';
const personalCodeSchema = z.string().refine(
(val) => {
try {
return new Isikukood(val).validate();
} catch {
return false;
}
},
{
message: 'Invalid personal code',
},
);
/**
* @name RESERVED_NAMES_ARRAY
* @description Array of reserved names for team accounts
@@ -46,11 +60,7 @@ export const CompanyNameSchema = z
*/
export const CreateCompanySchema = z.object({
name: CompanyNameSchema,
ownerPersonalCode: z
.string()
.regex(/^[1-6]\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}\d$/, {
message: 'Invalid Estonian personal code format',
}),
ownerPersonalCode: personalCodeSchema,
});
export type CreateCompanySchemaType = z.infer<typeof CreateCompanySchema>;