Help Angular by taking a 1 minute survey!Go to surveyHome

EmailValidator

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.

See also

NgModules

Selectors

Properties

Property Description
@Input()
email: string | boolean
Write-only.

Tracks changes to the email attribute bound to this directive.

Description

Adding an email validator

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">
    

Methods

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
    
Parameters
control AbstractControl
Returns

ValidationErrors | null

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

registerOnValidatorChange(fn: () => void): void
      
      registerOnValidatorChange(fn: () => void): void
    
Parameters
fn () => void

The callback function

Returns

void