1 import { Validators } from '@angular/forms'
2 import { BuildFormValidator } from './form-validator.model'
4 export const USER_USERNAME_VALIDATOR: BuildFormValidator = {
7 Validators.minLength(1),
8 Validators.maxLength(50),
9 Validators.pattern(/^[a-z0-9][a-z0-9._]*$/)
12 'required': $localize`Username is required.`,
13 'minlength': $localize`Username must be at least 1 character long.`,
14 'maxlength': $localize`Username cannot be more than 50 characters long.`,
15 'pattern': $localize`Username should be lowercase alphanumeric; dots and underscores are allowed.`
19 export const USER_CHANNEL_NAME_VALIDATOR: BuildFormValidator = {
22 Validators.minLength(1),
23 Validators.maxLength(50),
24 Validators.pattern(/^[a-z0-9][a-z0-9._]*$/)
27 'required': $localize`Channel name is required.`,
28 'minlength': $localize`Channel name must be at least 1 character long.`,
29 'maxlength': $localize`Channel name cannot be more than 50 characters long.`,
30 'pattern': $localize`Channel name should be lowercase, and can contain only alphanumeric characters, dots and underscores.`
34 export const USER_EMAIL_VALIDATOR: BuildFormValidator = {
35 VALIDATORS: [ Validators.required, Validators.email ],
37 'required': $localize`Email is required.`,
38 'email': $localize`Email must be valid.`
42 export const USER_EXISTING_PASSWORD_VALIDATOR: BuildFormValidator = {
47 'required': $localize`Password is required.`
51 export const USER_PASSWORD_VALIDATOR: BuildFormValidator = {
54 Validators.minLength(6),
55 Validators.maxLength(255)
58 'required': $localize`Password is required.`,
59 'minlength': $localize`Password must be at least 6 characters long.`,
60 'maxlength': $localize`Password cannot be more than 255 characters long.`
64 export const USER_PASSWORD_OPTIONAL_VALIDATOR: BuildFormValidator = {
66 Validators.minLength(6),
67 Validators.maxLength(255)
70 'minlength': $localize`Password must be at least 6 characters long.`,
71 'maxlength': $localize`Password cannot be more than 255 characters long.`
75 export const USER_CONFIRM_PASSWORD_VALIDATOR: BuildFormValidator = {
78 'matchPassword': $localize`The new password and the confirmed password do not correspond.`
82 export const USER_VIDEO_QUOTA_VALIDATOR: BuildFormValidator = {
83 VALIDATORS: [ Validators.required, Validators.min(-1) ],
85 'required': $localize`Video quota is required.`,
86 'min': $localize`Quota must be greater than -1.`
89 export const USER_VIDEO_QUOTA_DAILY_VALIDATOR: BuildFormValidator = {
90 VALIDATORS: [ Validators.required, Validators.min(-1) ],
92 'required': $localize`Daily upload limit is required.`,
93 'min': $localize`Daily upload limit must be greater than -1.`
97 export const USER_ROLE_VALIDATOR: BuildFormValidator = {
98 VALIDATORS: [ Validators.required ],
100 'required': $localize`User role is required.`
104 export const USER_DISPLAY_NAME_REQUIRED_VALIDATOR = buildDisplayNameValidator(true)
106 export const USER_DESCRIPTION_VALIDATOR: BuildFormValidator = {
108 Validators.minLength(3),
109 Validators.maxLength(1000)
112 'minlength': $localize`Description must be at least 3 characters long.`,
113 'maxlength': $localize`Description cannot be more than 1000 characters long.`
117 export const USER_TERMS_VALIDATOR: BuildFormValidator = {
118 VALIDATORS: [ Validators.requiredTrue ],
120 'required': $localize`You must agree with the instance terms in order to register on it.`
124 export const USER_BAN_REASON_VALIDATOR: BuildFormValidator = {
126 Validators.minLength(3),
127 Validators.maxLength(250)
130 'minlength': $localize`Ban reason must be at least 3 characters long.`,
131 'maxlength': $localize`Ban reason cannot be more than 250 characters long.`
135 function buildDisplayNameValidator (required: boolean) {
138 Validators.minLength(1),
139 Validators.maxLength(120)
142 'required': $localize`Display name is required.`,
143 'minlength': $localize`Display name must be at least 1 character long.`,
144 'maxlength': $localize`Display name cannot be more than 50 characters long.`
148 if (required) control.VALIDATORS.push(Validators.required)