Am performing form validations using angular6 documentations and for now I ensured that all form validations are filled but now
Here is my question:
1.) How do I validate that Password and Confirm Password input value is not less than 6 characters and that both password field and confirm password field must match
2.) How do I ensure that email address entered is valid
<form #r="ngForm" name="theForm" (submit)="reg(r)">
<div class="form-group">
<label>Username</label>
<input type="text"
class="form-control"
name="username"
[(ngModel)]="register.username"
#registerUsername="ngModel"
required
pattern="^[a-zA-Z]+$">
<span class="help-block danger" *ngIf="registerUsername.errors?.required && registerUsername.touched">
The username is required
</span>
<span class="help-block danger" *ngIf="registerUsername.errors?.pattern && registerUsername.touched">
The username can only contain the letters a-z or A-Z
</span>
</div>
<div class="form-group">
<label>Password</label>
<input type="password"
class="form-control"
name="password"
required
[(ngModel)]="register.password"
#registerPassword="ngModel">
<span class="help-block danger" *ngIf="registerPassword.errors?.required && registerPassword.touched">
password is required
</span>
</div>
<div class="form-group">
<label>Confirm Password</label>
<input type="password"
class="form-control"
name="password"
required
[(ngModel)]="register.password"
#registerPassword="ngModel">
<span class="help-block danger" *ngIf="registerPassword.errors?.required && registerPassword.touched">
Re-enter password is required
</span>
</div>
<div class="form-group">
<label>Email</label>
<input type="email"
class="form-control"
name="email"
required
[(ngModel)]="register.email"
#registerEmail="ngModel">
<span class="help-block danger" *ngIf="registerEmail.errors?.required && registerEmail.touched">
Email is required
</span>
</div>
emailattribute or through thepatternone. Seeing you're using template-driven forms, you will have to create a directive on theformtag to validate password matching. For the length, aminlengthattribute will be enough.