I am getting a `Type 'HTMLElement | null' is not assignable to type 'HTMLElement'. I am trying to validate an email address onkeyup event in angular.
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-mynform',
templateUrl: './mynform.component.html',
styleUrls: ['./mynform.component.css']
})
export class MynformComponent implements OnInit {
constructor() { }
ngOnInit(): void {
function EmailValidation(): void {
var email: string = (<HTMLInputElement>document.getElementById("txtEmail")).value;
var error: HTMLElement = document.getElementById("error");
error.innerHTML = "";
var expr: RegExp = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!expr.test(email)) {
error.innerHTML = "Enter valid email address format";
}
}
}
}
<input type="text" name="email" class="notify" autocomplete="off" id="txtEmail"
onkeyup="EmailValidation();" />
<span id="error"></span>