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_HANDLE_VALIDATOR: BuildFormValidator = {
45 Validators.pattern(/@.+/)
48 'required': $localize`Handle is required.`,
49 'pattern': $localize`Handle must be valid (chocobozzz@example.com).`
53 export const USER_EXISTING_PASSWORD_VALIDATOR: BuildFormValidator = {
58 'required': $localize`Password is required.`
62 export const USER_PASSWORD_VALIDATOR: BuildFormValidator = {
65 Validators.minLength(6),
66 Validators.maxLength(255)
69 'required': $localize`Password is required.`,
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_PASSWORD_OPTIONAL_VALIDATOR: BuildFormValidator = {
77 Validators.minLength(6),
78 Validators.maxLength(255)
81 'minlength': $localize`Password must be at least 6 characters long.`,
82 'maxlength': $localize`Password cannot be more than 255 characters long.`
86 export const USER_CONFIRM_PASSWORD_VALIDATOR: BuildFormValidator = {
89 'matchPassword': $localize`The new password and the confirmed password do not correspond.`
93 export const USER_VIDEO_QUOTA_VALIDATOR: BuildFormValidator = {
94 VALIDATORS: [ Validators.required, Validators.min(-1) ],
96 'required': $localize`Video quota is required.`,
97 'min': $localize`Quota must be greater than -1.`
100 export const USER_VIDEO_QUOTA_DAILY_VALIDATOR: BuildFormValidator = {
101 VALIDATORS: [ Validators.required, Validators.min(-1) ],
103 'required': $localize`Daily upload limit is required.`,
104 'min': $localize`Daily upload limit must be greater than -1.`
108 export const USER_ROLE_VALIDATOR: BuildFormValidator = {
109 VALIDATORS: [ Validators.required ],
111 'required': $localize`User role is required.`
115 export const USER_DISPLAY_NAME_REQUIRED_VALIDATOR = buildDisplayNameValidator(true)
117 export const USER_DESCRIPTION_VALIDATOR: BuildFormValidator = {
119 Validators.minLength(3),
120 Validators.maxLength(1000)
123 'minlength': $localize`Description must be at least 3 characters long.`,
124 'maxlength': $localize`Description cannot be more than 1000 characters long.`
128 export const USER_TERMS_VALIDATOR: BuildFormValidator = {
129 VALIDATORS: [ Validators.requiredTrue ],
131 'required': $localize`You must agree with the instance terms in order to register on it.`
135 export const USER_BAN_REASON_VALIDATOR: BuildFormValidator = {
137 Validators.minLength(3),
138 Validators.maxLength(250)
141 'minlength': $localize`Ban reason must be at least 3 characters long.`,
142 'maxlength': $localize`Ban reason cannot be more than 250 characters long.`
146 function buildDisplayNameValidator (required: boolean) {
149 Validators.minLength(1),
150 Validators.maxLength(120)
153 'required': $localize`Display name is required.`,
154 'minlength': $localize`Display name must be at least 1 character long.`,
155 'maxlength': $localize`Display name cannot be more than 50 characters long.`
159 if (required) control.VALIDATORS.push(Validators.required)