Regex 如何验证角材料反应表上的移动编号?

Regex 如何验证角材料反应表上的移动编号?,regex,angular,angular-material,angular-reactive-forms,angular-forms,Regex,Angular,Angular Material,Angular Reactive Forms,Angular Forms,应用程序组件.ts phoneFormControl = new FormControl('', [ Validators.required, Validators.pattern("[6-9]\d{9}") ]) app.component.html <mat-form-field> <input matInput placeholder="Phone Number" [formControl]="phoneFormControl> <mat-e

应用程序组件.ts

phoneFormControl = new FormControl('', [
Validators.required,
Validators.pattern("[6-9]\d{9}")
])
app.component.html

<mat-form-field>
    <input matInput placeholder="Phone Number" [formControl]="phoneFormControl>
    <mat-error *ngIf="phoneFormControl.hasError('required')">
         Phone Number is <strong>required</strong>
    </mat-error>
</mat-form-field>

因为您的模式是一个
字符串
,所以应该将反斜杠转义

因此,您需要的不是
Validators.pattern(“[6-9]\d{9}”)
,而是
Validators.pattern(“[6-9]\\d{9}”)

样本

readonly phoneFormControl = new FormControl('', [
  Validators.required, Validators.pattern(("[6-9]\\d{9}"))
]);

因为您的模式是一个
字符串
,所以应该将反斜杠转义

因此,您需要的不是
Validators.pattern(“[6-9]\d{9}”)
,而是
Validators.pattern(“[6-9]\\d{9}”)

样本

readonly phoneFormControl = new FormControl('', [
  Validators.required, Validators.pattern(("[6-9]\\d{9}"))
]);