<label for="userEmail">User Email:</label><br />
<input type="email" class="userMobile" id="userEmail" name="userEmail"
[(ngModel)]="selectedLocker.lockeruseremail" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+.(com|in)$"/><br />
The pattern requires the email to be in the format [email protected] or [email protected], but it still allows submission without .com or .in.
2
Answers
This email validation pattern has several issues, try to use this pattern :
For the template-driven form, you should use
form.valid
to check the form is valid before submission. And apply the[disabled]
attribute to block the button submission.You can display the error for the control with the
ngModel
directive as below:Demo @ StackBlitz