Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-05-07 23:28:12 +03:30
parent b2a1eb8e5b
commit ce40bd8c75
54 changed files with 260 additions and 183 deletions
+1
View File
@@ -5,3 +5,4 @@ export * from './mobile.validator';
export * from './must-match.validator';
export * from './password.validator';
export * from './postal-code.validator';
export * from './username.validator';
@@ -0,0 +1,31 @@
import { ValidatorFn } from '@angular/forms';
export function usernameValidator(): 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 {
invalidUsername: {
value: control.value,
message:
'نام کاربری فقط می‌تواند شامل حروف انگلیسی، اعداد، خط تیره (-) و زیر‌خط (_) باشد',
},
};
}
return null;
};
}