JavaScript Regular expression to remove characters other than number and allow single decimal dot only in Angular 6 regular expression remove characters,regular expression remove spaces,regular expression

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(/[^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>
Answer:1

You can use keypress event:

<input (keypress)="isNumberKey($event)"/>

and typescript:

isNumberKey(evt){
      console.log(evt.keyCode);
      let charCode = (evt.which) ? evt.which : evt.keyCode;
      if (charCode != 46 && charCode > 31 
        && (charCode < 48 || charCode > 57))
          return false;

      return true;
   }

Work example can be seen here

Answer:2

Here is the demo for what you need. Easy and simple regex.

function myFunction(){
var demo = document.getElementById('demo');
demo.value = demo.value.replace(/[^0-9.]/g, '');
}
<input type="text" id="demo" onkeyup="myFunction()">
Answer:3

This is a clean version of the my situation: const person1 = { name: "Person1 Name", hairColor: "Brown", backpack: { color: "Army-Green", content: [ "item1", ...

This is a clean version of the my situation: const person1 = { name: "Person1 Name", hairColor: "Brown", backpack: { color: "Army-Green", content: [ "item1", ...

I am using basic geolocation to grab user long/lat, I then add the coordinate pair to a global variable (global.usr), then generating a new map element with global.usr as my center of the map. Seems ...

I am using basic geolocation to grab user long/lat, I then add the coordinate pair to a global variable (global.usr), then generating a new map element with global.usr as my center of the map. Seems ...

  1. google maps javascript api
  2. google maps javascript api error apinotactivatedmaperror
  3. google maps javascript api error referernotallowedmaperror
  4. google maps javascript api key
  5. google maps javascript api error invalidkeymaperror
  6. google maps javascript api pricing
  7. google maps javascript api error apitargetblockedmaperror
  8. google maps javascript api warning noapikeys
  9. google maps javascript api error expiredkeymaperror
  10. google maps javascript api error deletedapiprojectmaperror
  11. google maps javascript api tutorial
  12. google maps javascript api example
  13. google maps javascript api warning sensornotrequired
  14. google maps javascript error
  15. google maps javascript api marker
  16. google maps javascript api reference
  17. google maps javascript library
  18. google maps javascript api react
  19. google maps javascript api multiple markers
  20. google maps javascript api error notloadingapifromgooglemapserror

I have the following array, containing similar JSON objects, [{name: "Abc"}, {name: "Xyz"}, {name: "lmn"}] How can Ramda help me in achieving the following ["Abc", "Xyz", "lmn"]

I have the following array, containing similar JSON objects, [{name: "Abc"}, {name: "Xyz"}, {name: "lmn"}] How can Ramda help me in achieving the following ["Abc", "Xyz", "lmn"]

I have a complex json file that I have to handle with TypeScript / Javascript to make it hierarchical, in order to later build a questionnaire. Every entry of the json has a Id (unique), ParentId (0 ...

I have a complex json file that I have to handle with TypeScript / Javascript to make it hierarchical, in order to later build a questionnaire. Every entry of the json has a Id (unique), ParentId (0 ...

  1. build tree array from flat array in javascript
  2. build tree array php
  3. build tree from array
  4. build tree from array javascript
  5. build tree from array python
  6. build tree from array java
  7. build tree from array js
  8. build tree from array c
  9. build tree from array representation
  10. build tree sorted array
  11. build tree from flat array
  12. build binary tree from array
  13. build binary tree from array python
  14. build binary tree from array java
  15. javascript build tree from array of objects
  16. ruby build tree from array
  17. typescript build tree from array
  18. build tree array from flat array in java
  19. build tree array from flat array in c#
  20. build binary tree using array