use isikukood library to validate in zod
This commit is contained in:
@@ -1,5 +1,19 @@
|
|||||||
|
import Isikukood from 'isikukood';
|
||||||
import { z } from 'zod';
|
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
|
* @name RESERVED_NAMES_ARRAY
|
||||||
* @description Array of reserved names for team accounts
|
* @description Array of reserved names for team accounts
|
||||||
@@ -46,11 +60,7 @@ export const CompanyNameSchema = z
|
|||||||
*/
|
*/
|
||||||
export const CreateCompanySchema = z.object({
|
export const CreateCompanySchema = z.object({
|
||||||
name: CompanyNameSchema,
|
name: CompanyNameSchema,
|
||||||
ownerPersonalCode: z
|
ownerPersonalCode: personalCodeSchema,
|
||||||
.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',
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type CreateCompanySchemaType = z.infer<typeof CreateCompanySchema>;
|
export type CreateCompanySchemaType = z.infer<typeof CreateCompanySchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user