refactor: replace economic code fields with individual and legal variants, add equal length validation
This commit is contained in:
@@ -68,6 +68,13 @@ export class FormErrorsService {
|
||||
const info = errors['invalidUsername'];
|
||||
out.push({ key: 'invalidUsername', message: info.message ?? `${label} معتبر نیست.` });
|
||||
}
|
||||
if (errors['equalLength']) {
|
||||
const info = errors['equalLength'];
|
||||
out.push({
|
||||
key: 'equalLength',
|
||||
message: `تعداد کاراکترهای ${label} باید برابر با ${info.length} باشد.`,
|
||||
});
|
||||
}
|
||||
|
||||
if (errors['invalidFiscalId']) {
|
||||
const info = errors['invalidFiscalId'];
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';
|
||||
|
||||
export function equalLengthValidator(length: number): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationErrors | null => {
|
||||
const v = control.value;
|
||||
if (v === null || v === undefined || v === '') {
|
||||
return null;
|
||||
}
|
||||
const normalized = String(v);
|
||||
|
||||
return normalized.length !== length
|
||||
? {
|
||||
equalLength: {
|
||||
length,
|
||||
},
|
||||
}
|
||||
: null;
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './equalLength.validator';
|
||||
export * from './fiscal-id.validator';
|
||||
export * from './greater.validator';
|
||||
export * from './iban.validator';
|
||||
|
||||
Reference in New Issue
Block a user