我是学习Angular2的新手,我想制作一个验证表格,用于在RegEx模式之后验证电子邮件.
我的代码看起来像这样,但我不知道如果我做得对,或者我做错了,有人可以帮助我一点吗?
谢谢!
我修好了它.非常感谢大家.
<div class="alert-email"> <label for="contactemail">EMAIL: </label> <input type="email" id="contactemail" name="contactemail" required ng-pattern="/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/" [(ngModel)]="model.contactemail" #contactemail="ngModel" placeholder="Your email" /><br><br> <div *ngIf="contactemail.errors && (contactemail.dirty || contactemail.touched)" class="alert-email alert-danger-email"><br> <div [hidden]="!contactname.errors.required"> Email is required </div> <div [hidden]="!contactname.errors"> Please input a valid email. </div> </div> </div>
尝试类似的东西
原文链接:https://www.f2er.com/angularjs/143963.html<div class="alert-email"> <label>Email</label> <input id="contactemail" type="text" #contactemail="ngModel" [(ngModel)]="model.contactemail" required pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$"> <div class="md-errors-spacer" [hidden]="contactemail.valid || contactemail.untouched"> <div *ngIf="contactemail.errors && contactemail.errors.required"> Email is required </div> <div *ngIf="contactemail.errors && contactemail.errors.pattern"> Email is invalid </div> </div> </div>