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_PASSWORD_VALIDATOR: BuildFormValidator = {
45 Validators.minLength(6),
46 Validators.maxLength(255)
49 'required': $localize`Password is required.`,
50 'minlength': $localize`Password must be at least 6 characters long.`,
51 'maxlength': $localize`Password cannot be more than 255 characters long.`
55 export const USER_PASSWORD_OPTIONAL_VALIDATOR: BuildFormValidator = {
57 Validators.minLength(6),
58 Validators.maxLength(255)
61 'minlength': $localize`Password must be at least 6 characters long.`,
62 'maxlength': $localize`Password cannot be more than 255 characters long.`
66 export const USER_CONFIRM_PASSWORD_VALIDATOR: BuildFormValidator = {
69 'matchPassword': $localize`The new password and the confirmed password do not correspond.`
73 export const USER_VIDEO_QUOTA_VALIDATOR: BuildFormValidator = {
74 VALIDATORS: [ Validators.required, Validators.min(-1) ],
76 'required': $localize`Video quota is required.`,
77 'min': $localize`Quota must be greater than -1.`
80 export const USER_VIDEO_QUOTA_DAILY_VALIDATOR: BuildFormValidator = {
81 VALIDATORS: [ Validators.required, Validators.min(-1) ],
83 'required': $localize`Daily upload limit is required.`,
84 'min': $localize`Daily upload limit must be greater than -1.`
88 export const USER_ROLE_VALIDATOR: BuildFormValidator = {
89 VALIDATORS: [ Validators.required ],
91 'required': $localize`User role is required.`
95 export const USER_DISPLAY_NAME_REQUIRED_VALIDATOR = buildDisplayNameValidator(true)
97 export const USER_DESCRIPTION_VALIDATOR: BuildFormValidator = {
99 Validators.minLength(3),
100 Validators.maxLength(1000)
103 'minlength': $localize`Description must be at least 3 characters long.`,
104 'maxlength': $localize`Description cannot be more than 1000 characters long.`
108 export const USER_TERMS_VALIDATOR: BuildFormValidator = {
110 Validators.requiredTrue
113 'required': $localize`You must agree with the instance terms in order to register on it.`
117 export const USER_BAN_REASON_VALIDATOR: BuildFormValidator = {
119 Validators.minLength(3),
120 Validators.maxLength(250)
123 'minlength': $localize`Ban reason must be at least 3 characters long.`,
124 'maxlength': $localize`Ban reason cannot be more than 250 characters long.`
128 function buildDisplayNameValidator (required: boolean) {
131 Validators.minLength(1),
132 Validators.maxLength(120)
135 'required': $localize`Display name is required.`,
136 'minlength': $localize`Display name must be at least 1 character long.`,
137 'maxlength': $localize`Display name cannot be more than 50 characters long.`
141 if (required) control.VALIDATORS.push(Validators.required)