Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

preventing letters from being placed in an input ts

  validateNumber(event) {
    const keyCode = event.keyCode;

    const excludedKeys = [8, 37, 39, 46];

    if (!((keyCode >= 48 && keyCode <= 57) ||
      (keyCode >= 96 && keyCode <= 105) ||
      (excludedKeys.includes(keyCode)))) {
      event.preventDefault();
    }
  }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #preventing #letters #input #ts
ADD COMMENT
Topic
Name
4+9 =