【发布时间】:2019-01-28 09:37:01
【问题描述】:
我有一个手机输入字段,用户可以在其中输入他/她的号码,但目前用户可以在输入字段中输入字母。我希望用户只会 输入 10 位数字而不是字母。 这是我的代码
<section class="col-sm-12 bg-white pl-20 pr-20">
<div>
<form novalidate [formGroup]="cfForm">
<div class="form-group col-sm-4 pl-0">
<label class="field-title mb-5">Mobile Number</label>
<input type="password" placeholder="Enter Mobile no" formControlName="mobile_no">
</div>
</form>
{{cfForm.valid | json }}
{{cfForm.value | json}}
</div>
</section
TS 文件
constructor(private fb: FormBuilder){
this.cfForm = this.fb.group({
mobile_no: ['', [Validators.required, Validators.pattern('^[0-9]{10}$')]],
});
我不想使用 type="number" 或 "text" 。我只想使用 "password" 因为我不想向任何人显示我的号码 见代码 https://stackblitz.com/edit/angular-jfqkfo?file=src%2Fapp%2Fapp.component.ts
【问题讨论】:
-
你为什么要使用 type="password" 这个?为什么不 type="text" (我不会使用数字,因为这会删除您手机号码的任何前导零)
-
第二件事我需要掩盖我为什么使用 type="password" 的 phohe 号码
-
因为我想屏蔽我的电话号码
-
你的 Angular 验证器不工作了吗?
-
@monty 请提出更好的解决方案
标签: javascript angular angular-reactive-forms