本文介绍了角度材料设计中的电话号码模式验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用角度材料设计代码验证电话号码,但即使我输入有效的电话号码,以下代码也不起作用,请帮我一些
I want to validate phone number using angular material designing code but below code is not working even when i enter valid phone number ca n some on help me please
<mat-form-field class="example-full-width">
<input matInput placeholder="Phone number" formControlName="PhoneNumber"
[errorStateMatcher]="matcher" [(ngModel)]="PhoneNumber" required pattern="[6-9]\\d{9}" maxlength="10">
<mat-hint>Errors appear instantly!</mat-hint>
<mat-error *ngIf="emailForm.get('PhoneNumber').hasError('required')">
Phone number is <strong>required</strong>
</mat-error>
<mat-error *ngIf="!emailForm.get('PhoneNumber').hasError('required') &&emailForm.get('PhoneNumber').hasError('pattern')">
Please enter valid mumber
</mat-error>
</mat-form-field>
ngOnInit() {
//Form Group
this.emailForm = new FormGroup({
PhoneNumber:new FormControl('',[Validators.pattern(/^[6-9]\d{9}$/)]),
});
}
https:///stackblitz.com/edit/angular-2m1vdq-7vzaq8?file=app%2Finput-error-state-matcher-example.html
推荐答案
你可以试试下面对我有用的正则表达式
you can try the below regex it worked for me
/^[0-9]{10,10}$/
/^[0-9]{10,10}$/
这篇关于角度材料设计中的电话号码模式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!