metis-desk/modules/companies/src/api/domain/value-objects/phone-number.ts
David e3f92fa534 feat: initialize pnpm workspace and add configuration files
- Added pnpm-workspace.yaml to define package structure.
- Created prepare-local-env.py script for local environment setup.
- Introduced tsconfig.json for TypeScript configuration.
- Added turbo.json for task management with Turbo.
2026-10-03 12:36:03 +02:00

17 lines
528 B
TypeScript

import { ValueObject } from "@repo/rdx-ddd";
import { Result } from "@repo/rdx-utils";
export class PhoneNumber extends ValueObject<string> {
static create(value: string): Result<PhoneNumber, Error> {
const normalized = value.trim();
if (
normalized.length > 50 ||
!/^\+?[0-9 ().-]{3,50}(?: ?(?:x|ext\.?) ?[0-9]{1,8})?$/.test(normalized) ||
!/[0-9]/.test(normalized)
) {
return Result.fail(new Error("Teléfono inválido."));
}
return Result.ok(new PhoneNumber(normalized));
}
}