In Angular 7, I have implemented a Reactive Form with an input field named email
. This input field is configured with two validators as shown below:
email: ['', [Validators.email, Validators.pattern('^[\\w._]+@company(.com|.go|.jet)')]],
Each validator has an associated error message in the template:
<label for="email" class="error-msg" *ngIf="authForm.get('email').hasError('email') && hideFocus">Your email is invalid</label>
<label for="email" class="error-msg" *ngIf="authForm.get('email').hasError('pattern') && hideFocus">Only emails ending with .com .go and .jet are allowed</label>
Currently, when the user inputs text into the field, both error messages are displayed simultaneously.
Is there a way to show only one error message at a time? Can this be achieved?