填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

EmailValidator

该指令会借助 NG_VALIDATORS 绑定把 email 验证器添加到任何带有 email 属性的控件上。

A directive that adds the email validator to controls marked with the email attribute. The directive is provided with the NG_VALIDATORS multi-provider list.

参见

NgModules

选择器

属性

属性说明
@Input()
email: string | boolean
Write-only.

Tracks changes to the email attribute bound to this directive.

说明

添加 email 验证器

Adding an email validator

下面的例子演示了如何为一个带有 ngModel 绑定的输入框添加 email 验证器。

The following example shows how to add an email validator to an input attached to an ngModel binding.

<input type="email" name="email" ngModel email> <input type="email" name="email" ngModel email="true"> <input type="email" name="email" ngModel [email]="true">
      
      <input type="email" name="email" ngModel email>
<input type="email" name="email" ngModel email="true">
<input type="email" name="email" ngModel [email]="true">
    

方法

Method that validates whether an email address is valid. Returns the validation result if enabled, otherwise null.

validate(control: AbstractControl): ValidationErrors | null
      
      validate(control: AbstractControl): ValidationErrors | null
    
参数
control AbstractControl
返回值

ValidationErrors | null

Registers a callback function to call when the validator inputs change.

registerOnValidatorChange(fn: () => void): void
      
      registerOnValidatorChange(fn: () => void): void
    
参数
fn () => void

The callback function

返回值

void