Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67527

Regular expression to remove characters other than number and decimal dot in Typescript

$
0
0

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:

allownumbersonly(inputVal) {
    inputVal = inputVal.replace(/^(\d+(?:[\.\,]\d{2})?)$/, "");
    //inputVal = inputVal.replace(/[^0-9 ]+(\.)?/g, "");
    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.


Viewing all articles
Browse latest Browse all 67527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>