I implemented the email validation through the tutorials. The problem is Email validation accepts something like "asd@asd" which is not a valid mail.
Secondly i get the error "ngModel cannot be used to register form controls with a parent formGroup directive. Try using formGroup's partner directive "formControlName" instead. " tried all the answers on stackoverflow but none of them worked. What am i doing wrong ?
this.loginForm = this.formBuilder.group({
email: ['', [Validators.required, Validators.email,
Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$')]],
});
And the template :
<input class="form-control" formControlName="email" type="text"[(ngModel)]="username" name="username" placeholder="E-mail"
[ngClass]="{ 'is-invalid': submitted && f.email.errors }" />
<div *ngIf="submitted && f.email.errors" class="invalid-feedback">
<div *ngIf="f.email.errors.required">Email is required</div>
<div *ngIf="f.email.errors.email">Email must be a valid email address</div>
</div>
formControlNamein your<input>tag. Don't usengModel- ChaitanyangModelin form group. How ever if you want to use it for some reason, you have to declare it as a standalone.[ngModelOptions]="{standalone: true}"- Dino