() => expect(Validators.required(new FormControl([1, 2]))).toBeNull());
() => expect(Validators.requiredTrue(new FormControl(false))).toEqual({'required': true}));
beforeEach(() => { component.customBadges = true; component.customBadgeValidators = [Validators.pattern('[A-Za-z0-9_]+')]; component.ngOnInit(); });
() => expect(Validators.required(new FormControl([]))).toEqual({'required': true}));
it('should error on short strings', () => { expect(Validators.minLength(2)(new FormControl('a'))).toEqual({ 'minlength': {'requiredLength': 2, 'actualLength': 1} }); });
it('should error when FormArray has invalid length', () => { const fa = new FormArray([new FormControl('')]); expect(Validators.minLength(2)(fa)).toEqual({ 'minlength': {'requiredLength': 2, 'actualLength': 1} }); });
import { Validators } from '@angular/forms' export const USER_USERNAME = { VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20), Validators.pattern(/^[a-z0-9._]+$/) ], MESSAGES: { 'required': 'Username is required.', 'minlength': 'Username must be at least 3 characters long.', 'maxlength': 'Username cannot be more than 20 characters long.', 'pattern': 'Username should be only lowercase alphanumeric characters.' } } export const USER_EMAIL = { VALIDATORS: [ Validators.required, Validators.email ], MESSAGES: { 'required': 'Email is required.', 'email': 'Email must be valid.' } } export const USER_PASSWORD = { VALIDATORS: [ Validators.required, Validators.minLength(6) ], MESSAGES: { 'required': 'Password is required.', 'minlength': 'Password must be at least 6 characters long.' } } export const USER_VIDEO_QUOTA = {
() => expect(Validators.email(new FormControl('*****@*****.**'))).toBeNull());
private emailOrEmpty(control: AbstractControl): ValidationErrors | null { return control.value === '' ? null : Validators.email(control); }
constructor (private i18n: I18n) { this.USER_USERNAME = { VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20), Validators.pattern(/^[a-z0-9._]+$/) ], MESSAGES: { 'required': this.i18n('Username is required.'), 'minlength': this.i18n('Username must be at least 3 characters long.'), 'maxlength': this.i18n('Username cannot be more than 20 characters long.'), 'pattern': this.i18n('Username should be only lowercase alphanumeric characters.') } } this.USER_EMAIL = { VALIDATORS: [ Validators.required, Validators.email ], MESSAGES: { 'required': this.i18n('Email is required.'), 'email': this.i18n('Email must be valid.') } } this.USER_PASSWORD = { VALIDATORS: [ Validators.required, Validators.minLength(6), Validators.maxLength(255) ], MESSAGES: { 'required': this.i18n('Password is required.'), 'minlength': this.i18n('Password must be at least 6 characters long.'), 'maxlength': this.i18n('Password cannot be more than 255 characters long.') } } this.USER_VIDEO_QUOTA = { VALIDATORS: [ Validators.required, Validators.min(-1) ], MESSAGES: { 'required': this.i18n('Video quota is required.'), 'min': this.i18n('Quota must be greater than -1.') } } this.USER_ROLE = { VALIDATORS: [ Validators.required ], MESSAGES: { 'required': this.i18n('User role is required.') } } this.USER_DISPLAY_NAME = { VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ], MESSAGES: { 'required': this.i18n('Display name is required.'), 'minlength': this.i18n('Display name must be at least 3 characters long.'), 'maxlength': this.i18n('Display name cannot be more than 120 characters long.') } } this.USER_DESCRIPTION = { VALIDATORS: [ Validators.minLength(3), Validators.maxLength(250) ], MESSAGES: { 'minlength': this.i18n('Description must be at least 3 characters long.'), 'maxlength': this.i18n('Description cannot be more than 250 characters long.') } } }