-1

This current function prevents the user from typing any character but numbers. I would like to adjust it to allow commas and the spacebar as well. How would I adjust it.

numbersFunction(event: any): boolean {
    const charCode = (event.which) ? event.which : event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
      return false;
    }
    return true;
  }
Flash
  • 924
  • 3
  • 22
  • 44

1 Answers1

0

If your goal is to restrict to floating numbers only, you could use the Validators.pattern to enforce the correct pattern.

There is example of patterns in other questions, like this one.

LaurentG
  • 11,128
  • 9
  • 51
  • 66