feat: implement fiscal ID validation; replace fiscal code validator and update related components
This commit is contained in:
@@ -68,6 +68,11 @@ export class FormErrorsService {
|
||||
const info = errors['invalidUsername'];
|
||||
out.push({ key: 'invalidUsername', message: info.message ?? `${label} معتبر نیست.` });
|
||||
}
|
||||
|
||||
if (errors['invalidFiscalId']) {
|
||||
const info = errors['invalidFiscalId'];
|
||||
out.push({ key: 'invalidFiscalId', message: info.message ?? `${label} معتبر نیست.` });
|
||||
}
|
||||
// fallback: include any other error keys
|
||||
Object.keys(errors).forEach((k) => {
|
||||
if (
|
||||
@@ -80,6 +85,7 @@ export class FormErrorsService {
|
||||
'max',
|
||||
'email',
|
||||
'pattern',
|
||||
'invalidFiscalId',
|
||||
].indexOf(k) === -1
|
||||
) {
|
||||
try {
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { ValidatorFn } from '@angular/forms';
|
||||
|
||||
export function fiscalCodeValidator(): ValidatorFn {
|
||||
return (control) => {
|
||||
if (control.value === null || control.value === undefined || control.value === '') {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return control.value.length === 11 && /^[0-9]{11}$/.test(control.value)
|
||||
? null
|
||||
: { fiscalCode: 'معتبر نیست' };
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { ValidatorFn } from '@angular/forms';
|
||||
|
||||
export function fiscalIdValidator(): ValidatorFn {
|
||||
return (control) => {
|
||||
if (control.value === null || control.value === undefined || control.value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (control.value.length < 6) {
|
||||
return {
|
||||
minlength: {
|
||||
requiredLength: 6,
|
||||
actualLength: control.value.length,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const pattern = /^[a-zA-Z0-9]*$/;
|
||||
|
||||
if (!pattern.test(control.value)) {
|
||||
return {
|
||||
invalidFiscalId: {
|
||||
value: control.value,
|
||||
message: 'شناسه مالی فقط میتواند شامل حروف انگلیسی و اعداد باشد',
|
||||
},
|
||||
};
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from './fiscal-code.validator';
|
||||
export * from './fiscal-id.validator';
|
||||
export * from './greater.validator';
|
||||
export * from './iban.validator';
|
||||
export * from './mobile.validator';
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
import { ValidatorFn } from '@angular/forms';
|
||||
|
||||
// Password must be minimum 8 characters, include at least one uppercase,
|
||||
// one lowercase, one number and one special character
|
||||
// export const PASSWORD_PATTERN = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/;
|
||||
export const PASSWORD_PATTERN = /^[0-9]{6,}$/;
|
||||
// const PASSWORD_PATTERN = /^[a-zA-Z0-9_-]*$/;
|
||||
|
||||
// Validator factory named `password` as requested. Returns `null` for empty
|
||||
// values so `Validators.required` can be used alongside it when needed.
|
||||
export function password(): ValidatorFn {
|
||||
return (control) => {
|
||||
const value = control?.value;
|
||||
if (value === null || value === undefined || String(value).length === 0) return null;
|
||||
return PASSWORD_PATTERN.test(String(value)) ? null : { password: 'معتبر نیست' };
|
||||
|
||||
if (value.length < 6) {
|
||||
return {
|
||||
minlength: {
|
||||
requiredLength: 6,
|
||||
actualLength: value.length,
|
||||
},
|
||||
};
|
||||
}
|
||||
return null;
|
||||
// return PASSWORD_PATTERN.test(String(value)) ? null : { password: 'معتبر نیست' };
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user