title: How to restrict special characters in the input field using Angular 2 / Typescript
body: <p>I am new to Angular 2. I need to prevent special characters from being typed in the input field. If I type alphanumerics, it must accept them, while special characters should be blocked. Can anyone help please.</p>
  
  <p>I am sharing the code here.</p>
  
  <p>In HTML:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;md-input-container&gt;
     &lt;input type="text" (ngModelChange)="omit_special_char($event)" mdInput name="name" [(ngModel)]="company.name" placeholder="Company Name" #name="ngModel" minlength="3" required&gt;
  &lt;/md-input-container&gt;
  </code></pre>
  
  <p>In TS:</p>
  
  <pre><code>public e: any;
  
  omit_special_char(val)
  {
     var k;
     document.all ? k = this.e.keyCode : k = this.e.which;
     return ((k &gt; 64 &amp;&amp; k &lt; 91) || (k &gt; 96 &amp;&amp; k &lt; 123) || k == 8 || k == 32 || (k &gt;= 48 &amp;&amp; k &lt;= 57));
  }
  </code></pre>