• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript forms.Validators类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript index.disableDeprecatedForms函数代码示例发布时间:2022-05-28
下一篇:
TypeScript forms.ValidatorFn类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap