Specific Validation Errors
- Angular has few built-in validators based on HMTL 5 validation attributes
- You can add multiple validation constraint on an input field
- Use pattern for regular expression validation
- Error has 1 or more key value pairs. key is the validation error
<input ngModel name="firstName" minlength="3" maxlength="10" pattern="ganesh" required>
<div *ngIf="firstName.touched && !firstName.valid" class="alert alert-danger">
<div *ngIf="firstName.errors.required">Firstname is required</div
<div *ngIf="firstName.errors.minlength">Firstname shoud be 3 characters</div
<div *ngIf="firstName.errors.pattern">Firstname doesn't match the pattern</div
</div>
- To display length dynamically
<div *ngIf="firstName.errors.minlength">Firstname shoud be minimum {{firstName.errors.minlength.requiredLength}}</div