Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1x 1x 18x 18x 18x 1x | import { ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator';
@ValidatorConstraint({ name: 'AngolanIBAN', async: false })
export class AngolanIBANValidator implements ValidatorConstraintInterface {
validate(iban: string): boolean {
// Verifica se o valor é nulo, undefined ou não é string
Iif (iban === null || iban === undefined || typeof iban !== 'string') {
return false;
}
// Remove todos os caracteres não alfanuméricos (incluindo espaços e hífens)
const cleaned = iban.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
// Verifica o formato básico: AO seguido de 21 dígitos
return /^AO\d{21}$/.test(cleaned);
}
defaultMessage(): string {
return 'IBAN angolano inválido. O formato deve ser "AO" seguido de 21 dígitos (total 23 caracteres)';
}
} |