26 lines
940 B
TypeScript
26 lines
940 B
TypeScript
import { DomainError } from '@/shared/exceptions/domain.exception';
|
|
|
|
export class KYCInfo {
|
|
constructor(
|
|
public readonly realName: string,
|
|
public readonly idCardNumber: string,
|
|
public readonly idCardFrontUrl: string,
|
|
public readonly idCardBackUrl: string,
|
|
) {
|
|
if (!realName || realName.length < 2) {
|
|
throw new DomainError('真实姓名不合法');
|
|
}
|
|
if (!/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[0-9Xx]$/.test(idCardNumber)) {
|
|
throw new DomainError('身份证号格式错误');
|
|
}
|
|
}
|
|
|
|
static create(params: { realName: string; idCardNumber: string; idCardFrontUrl: string; idCardBackUrl: string }): KYCInfo {
|
|
return new KYCInfo(params.realName, params.idCardNumber, params.idCardFrontUrl, params.idCardBackUrl);
|
|
}
|
|
|
|
maskedIdCardNumber(): string {
|
|
return this.idCardNumber.replace(/(\d{6})\d{8}(\d{4})/, '$1********$2');
|
|
}
|
|
}
|