Summary
I am creating a FormControl
with a validation pattern. When the pattern is invalid I want to call a function that will display the error message associated with the error that is being thrown.
Example
ngOnInit() {
this.personalForm = new FormGroup({
email : new FormControl(this.auth.user.email,Validators.required ),
first_name: new FormControl(null,[
Validators.required,
Validators.pattern("^[a-zA-Zñáéíóúü']{1,30}$")
]),
});
}
Function to call when input field is not valid.
showError();
Question
Is it possible to call a function if the error is thrown and retrieve the error when an input field is not valid?