I am using angular 6. I am trying to validate an email by using regular expression pattern but am not able. Problem is when I am trying these code to validate. Below error message is shwoing:
ReactiveFormComponent.html:12 ERROR TypeError: Cannot read property 'pattern' of null
//ts file
constructor(private fb: FormBuilder) {
this.personForm = fb.group({
'emailAddress': ['', Validators.compose ([Validators.required,
Validators.pattern(this.emailPattern)])],
});
}
// html file
<mat-form-field fxFlex>
<input matInput placeholder="Email" formControlName="emailAddress">
<mat-error *ngIf="personForm.controls['emailAddress'].errors.pattern">
Invalid Email.
</mat-error>
</mat-form-field>
emailPattern.