當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript forms.Validators類代碼示例

本文整理匯總了TypeScript中@angular/forms.Validators的典型用法代碼示例。如果您正苦於以下問題:TypeScript Validators類的具體用法?TypeScript Validators怎麽用?TypeScript Validators使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Validators類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: expect

 () => expect(Validators.required(new FormControl([1, 2]))).toBeNull());
開發者ID:diestrin,項目名稱:angular,代碼行數:1,代碼來源:validators_spec.ts

示例2: beforeEach

 beforeEach(() => {
   component.customBadges = true;
   component.customBadgeValidators = [Validators.pattern('[A-Za-z0-9_]+')];
   component.ngOnInit();
 });
開發者ID:LenzGr,項目名稱:ceph,代碼行數:5,代碼來源:select.component.spec.ts

示例3: it

 it('should error on short strings', () => {
   expect(Validators.minLength(2)(new FormControl('a'))).toEqual({
     'minlength': {'requiredLength': 2, 'actualLength': 1}
   });
 });
開發者ID:diestrin,項目名稱:angular,代碼行數:5,代碼來源:validators_spec.ts

示例4:

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 = {
開發者ID:quoidautre,項目名稱:PeerTube,代碼行數:31,代碼來源:user.ts

示例5: emailOrEmpty

 private emailOrEmpty(control: AbstractControl): ValidationErrors | null {
   return control.value === '' ? null : Validators.email(control);
 }
開發者ID:hcxiong,項目名稱:copay,代碼行數:3,代碼來源:add.ts

示例6: constructor

  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.')
      }
    }
  }
開發者ID:jiang263,項目名稱:PeerTube,代碼行數:77,代碼來源:user-validators.service.ts


注:本文中的@angular/forms.Validators類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。