title: Validate the input, Input field should not accept more than 100 value in angular 8
body: <p>I had to validate a input field to accept only number and decimal, one digit after the decimal. i was able to achieve it. i also need to limit the input field such that, it should not take more than 100. I have added a condition for that but its failing. I'm validating this on keypress can anyone please let me know where im going wrong.
  stackblitz editor link - <a href="https://stackblitz.com/edit/angular-with-alternative-6zczr4" rel="nofollow noreferrer">https://stackblitz.com/edit/angular-with-alternative-6zczr4</a>
  link - <a href="https://angular-with-alternative-6zczr4.stackblitz.io" rel="nofollow noreferrer">https://angular-with-alternative-6zczr4.stackblitz.io</a></p>
  <p>code:-
  app.component.html</p>
  <pre><code>&lt;div class=&quot;form-group mr-3&quot;&gt;
      &lt;p class=&quot;mb-0&quot;&gt;Accepts Number
      &lt;/p&gt;
      &lt;input type=&quot;number&quot; min=&quot;0&quot; max=&quot;100&quot; (keypress)=&quot;numberOnly($event)&quot; class=&quot;form-control form-width&quot; name=&quot;electricity&quot; [(ngModel)]=&quot;electricity&quot;&gt;
          &lt;/div&gt;
  
  </code></pre>
  <p>app.component.ts</p>
  <pre><code>  public electricity = &quot;&quot;;
  
    numberOnly(event): boolean {
      const charCode = event.which ? event.which : event.keyCode;
      const value = event.target.value;
      if ((&quot;&quot; + event.target.value).indexOf(&quot;.&quot;) !== -1) {
        if ((&quot;&quot; + event.target.value).split(&quot;.&quot;)[1].length &gt; 0) {
          return false;
        }
      }
      if (event.target.value &gt; 100) {
        return false;
      }
  
      if (charCode === 46) {
        return true;
      }
      if (charCode &gt; 31 &amp;&amp; (charCode &lt; 48 || charCode &gt; 57)) {
        return false;
      }
      return true;
    }
  </code></pre>