I have read similar questions and no solutions seem to be working for this.(我读过类似的问题,似乎没有解决方案。)
I have a Angular material input box.(我有一个角度材料输入框。) The input should receive only numbers and a decimal dot.(输入应仅接收数字和小数点。) All other characters should be identified and removed on keypress removal.(所有其他字符都应在删除按键时识别并删除。)
This is my code:(这是我的代码:)
In TS file and html:(在TS文件和html中:)
allownumbersonly(inputVal) { inputVal = inputVal.replace(/[^0-9.]/g, '');//Modified after responses from stack overflow. this.myForm.controls['inNum'].setValue(inputVal); }
<mat-form-field> <input id="inputNumber" matInput (keyup)="allownumbersonly($event.target.value)" placeholder="enter a number" formControlName="inNum"> </mat-form-field>
Please help.(请帮忙。) Thanks in advance.(提前致谢。)
ask by AngularDoubts translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…