【发布时间】:2019-04-11 08:04:27
【问题描述】:
这里有一个小场景,用户不应该输入特殊字符作为起始字符。此后他们应该被允许。
component.ts
this.new_org = this.fb.group({
firstName: [this.data.name, [Validators.required, Validators.minLength(8),Validators.pattern('^[a-zA-Z \-\']+')]],
});
component.html
<mat-form-field appearance="outline" fxFlex="100%">
<mat-label>Name</mat-label>
<input class="add-org" matInput placeholder="" formControlName="firstName" type="text" required>
</mat-form-field>
<mat-error
*ngIf="new_org.get('firstName').hasError('minlength') || new_org.get('firstName').hasError('pattern')">
<span style="color:red;font-family:Open-Sans">Name must be 8 characters Long!.Special characters(@,#,!) and Numbers
are not allowed.</span>
</mat-error>
如何限制第一个输入字符中的特殊字符?
【问题讨论】:
标签: angular typescript